How to send email from a php script

Discussion in 'Email Discussions' started by popowich, Apr 25, 2014.

  1. popowich

    popowich EQ Forum Admin Staff Member

    Joined:
    Aug 12, 2008
    Messages:
    9,001
    Likes Received:
    120
    To send email from a php script use the following code that requires an email recipient, subject line, the message body, and what address the email should be sent From:
    PHP:

    $to 
    "contact@example.com"
    $subject "The subject of the email"
    $body "This is an example email sent from a php script";
    $from "yourAddress@example.com";

    if (
    mail($to$subject$body$from)) {   
      echo(
    "<p>Success - Email sent"); 
    } else {     
        echo(
    "<p>Fail - Error sending email");   
      }
    To help prevent your email being marked as spam be sure to add a valid From: address so the email is not sent as your web server address.
     


Want to reply or ask your own question?

It only takes a minute to sign up (and it's free!). Click the orange sign up button to choose a username and then you can ask your own questions on the forum.
Loading...