Sending a plain text email in php is very simple:

$to = 'cindy@example.com';
$subject = 'Hello!';
$body = "This is the body of my email\n\nThis is line two";
$from = "From: admin@example2.com";
mail($to, $subject, $body, $from);

If I want to send the email to more than one person, I can just add more email addresses in the $to variable separated by a comma like this:


$to = 'cindy@example.com, cindy2@example.com';

Notice the ‘\n\n’ in the $body variable. This is the linefeed. I’ve had trouble in some email programs if I only include one ‘\n’, so I always include two. This gives me double spacing in most email programs, but at least gives a line break in all email programs that I’ve tested.

Also notice the double quotes around the body string. This is required if you are using the ‘n’. If you don’t have the double quotes, the ‘\n’ won’t be translated properly.

The $from variable contains the headers. You should at least have the ‘From:’ header. Make sure you have the ‘From: ‘ included with the email address. You can also add some other headers like this:


$from = "From: cindy@example2\nCC: cindy@example3.com\nBCC:cindy@example4.com";

Notice just one ‘\n’ here. I’ve not tested this on many mail programs, but it is working well for Mac mail. If you find different results in other mail programs, please leave a comment below.

Also notice the double quotes on that header so that the ‘\n’ will work correctly.

If you have large amounts of email to send in your php script, this function will not be very efficient. If you need to send HTML email or attachments, this function will not serve you well. For any of these options, you should try another php method of sending mail.

Leave a Comment

Your email address will not be published. Required fields are marked *