Category: Code • Tutorial Type: text • Added: 1253040660 •
Here are a few diffrent ways to send an email with php. This is a very simple php mail script, you can use a mail funtion then you dont have to retype the email code the whole time or you can phpMailer that you can authenticate with an email address.
Plain Text Email:
$email_to = "user@domain.co.za"; $subject = "This is a test email"; $headers = "FROM: user@example.com".""; $headers .= "Reply-To: user@example.com".""; $headers .= "MIME-Version: 1.0".""; $headers .= "Content-type: text/plain; charset=iso-8859-1".""; $mail_body = "This is the body of the simple email!!"; //check if the mail has been sent if (mail($email_to, $subject, $body, $headers) ) { echo "Email sent"; } else { echo "Email could not be sent"; }
HTML Email:
$email_to = "user@domain.co.za"; $subject = "This is a test email"; $headers = "FROM: user@example.com".""; $headers .= "Reply-To: user@example.com".""; $headers .= "MIME-Version: 1.0".""; $headers .= "Content-type: text/html; charset=iso-8859-1".""; $mail_body = "This is the body of the simple email!!"; //check if the mail has been sent if (mail($email_to, $subject, $body, $headers) ) { echo "Email sent"; } else { echo "Email could not be sent"; }