PHP mail()

Introduction
This article explains how to use PHP's  function to create and send emails. The function can accept a number of parameters:
 * 1) To (required string)
 * 2) Subject (required string)
 * 3) Message (required string) - note that each line should end in a new line control character, and you may wish to use the   function to limit the line length to 70 characters.
 * 4) Additional headers (optional)
 * 5) * From
 * 6) * CC
 * 7) * BCC
 * 8) * Other headers
 * 9) Additional parameters (optional)

Warning
Never use form input (such as names or email addresses) in the "Additional headers" section of the PHP mail command, as this can lead to mail header injection exploits which allow spammers to hijack your email forms. Please see this link for additional information on how these attacks work and how to prevent them: Email Injection

Basic example
<?php

// compose message $message = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."; $message .= " Nam iaculis pede ac quam. Etiam placerat suscipit nulla."; $message .= " Maecenas id mauris eget tortor facilisis egestas."; $message .= " Praesent ac augue sed enim aliquam auctor. Ut dignissim ultricies est."; $message .= " Pellentesque convallis tempor tortor. Nullam nec purus.";

// make sure each line doesn't exceed 70 characters $message = wordwrap($message, 70);

// send email mail('somebody@example.com', 'Nonsensical Latin', $message); ?>

Advanced example
<?php $to = "somebody@example.com"; $subject = "Nonsensical Latin";

// compose headers $headers = "From: webmaster@example.com\r\n"; $headers .= "Reply-To: webmaster@example.com\r\n"; $headers .= "X-Mailer: PHP/".phpversion;

// compose message $message = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit."; $message .= " Nam iaculis pede ac quam. Etiam placerat suscipit nulla."; $message .= " Maecenas id mauris eget tortor facilisis egestas."; $message .= " Praesent ac augue sed enim aliquam auctor. Ut dignissim ultricies est."; $message .= " Pellentesque convallis tempor tortor. Nullam nec purus."; $message = wordwrap($message, 70);

// send email mail($to, $subject, $message, $headers); ?>

Sending HTML mail
enim aliquam auctor.       Pellentesque convallis tempor tortor. Nullam nec purus. ";

// To send HTML mail, the Content-type header must be set $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

// send email mail($to, $subject, $message, $headers); ?>

Mail Header Injection
The following code can be placed in the top of your php script to deter the most common header injections. Please note this code disallows direct page access, so only add to a "process" page reachable by a Submit action. It will filter out any CC or BCC headers being injected as well as any new line or carriage return tags injected into the email header. 

550 5.7.1 Sender domain not allowed
Example Error: MMM 00 00:00:00 postfix/smtp[51817]: : to=, relay=relay.dreamhost.com[000.000.000.000]:25, delay=1.6, delays=0.02/0/0.01/1.6, dsn=5.7.1, status=bounced (host relay.dreamhost.com[000.000.000.000] said: 550 5.7.1 Sender domain not allowed. Please read: http://dhurl.org/20b (in reply to end of DATA command))

In order to correct this issue, the '[From]' field of the e-mail being sent needs to be a 'DreamHost-hosted' e-mail account which will allow the mail to be delivered without being bounced due to the outgoing spam prevention policies which were put into effect as detailed here: http://dhurl.org/20b.

Please see E-Mail for details on creating DreamHost hosted e-mail addresses via the DreamHost panel.

concrete5:

http://www.concrete5.org/community/forums/chat/contact-form-from-email/

Add the following to config/site.php: define('FORM_BLOCK_SENDER_EMAIL', 'mail@yourdomain.com'); define('EMAIL_DEFAULT_FROM_ADDRESS', 'mail@yourdomain.com'); define('EMAIL_DEFAULT_FROM_NAME', 'Your Name'); define('FORM_BLOCK_SENDER_EMAIL', EMAIL_DEFAULT_FROM_ADDRESS);