mail("to","subject","message","headers");
mail("to@example.com", "Test Email Message", "This is a test email message, please disregard.","from@example.com");
$to = "to@example.com"; //Other possibilities: "Name <to@example.com>"
$subject = "Test Email Message"; //Plain text
$message = "This is a test email message, please disregard."; //You can also use HTML or any other content type here.
$headers = "From: $from"; //The "From: " part is required!
$headers .= "\r\n"; //Separation mark
$headers .= "Content-type: text/plain"; //You aren't limited to just from, bcc etc headers.
$headers .= "\r\n\r\n"; //Double one to end it.
mail($from, $subject, $message, $headers);
The mail() function is indeed the basic way to send mail using php.
However, you made a mistake with the headers. All headers must be separated by "\r\n", not just by "\n". And this is wrong in your example too...
mail headers are like html headers, you can give loads more than just from.PHP:$to = "to@example.com"; //Other possibilities: "Name <to@example.com>" $subject = "Test Email Message"; //Plain text $message = "This is a test email message, please disregard."; //You can also use HTML or any other content type here. $headers = "From: $from"; //The "From: " part is required! $headers .= "\r\n"; //Separation mark $headers .= "Content-type: text/plain"; //You aren't limited to just from, bcc etc headers. $headers .= "\r\n\r\n"; //Double one to end it. mail($from, $subject, $message, $headers);
- Marshian
function constructHeader() // Construct the mail headers
{
$this->Header = 'MIME-Version: 1.0'."\r\n";
$this->Header .= 'Content-Type: text/html;charset=iso-8859-1'."\r\n";
$this->Header .= 'X-Priority: 3 (Normal)'."\r\n";
$this->Header .= 'X-MSMail-Priority: Normal'."\r\n";
$this->Header .= 'To: '.$this->ToName.' <'.$this->ToAdd.'>'."\r\n";
$this->Header .= 'Return-Path: '.$this->ToAdd."\r\n";
$this->Header .= 'From: '.$this->FromName.' <'.$this->FromAdd.'>'."\r\n";
$this->Header .= 'Reply-To: '.$this->FromName.' <'.$this->FromAdd.'>'."\r\n";
$this->Header .= 'X-Mailer: PHP/'.phpversion();
}