Reputation: 1753
I want to send an email via the mail()
function.
mail($to,$subject,$message)
works fine.
But using mail($to,$subject,$message,$header)
doesn't work.
The header is:
Date: Tue, 2 Jul 2013 15:01:49 +0200 +0200
Return-Path: [email protected]
From: "[email protected]"
Message-ID:
X-Priority: 3
X-Mailer: PHPMailer 5.2.4 (http://code.google.com/a/apache-extras.org/p/phpmailer/)
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/html; charset=UTF-8
What is wrong with my headers? FYI, the headers are generated by PHPMailer. The code I use to send it is:
$mail = new PHPMailer();
$mail->IsMail();
$mail->From = $from;
$mail->FromName = $from;
$mail->AddAddress($to);
$mail->IsHTML(true);
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->Body = $message;
$mail->Send();
Upvotes: 1
Views: 1051
Reputation: 86
Have you tried to use another header? I use
$header = "From: [email protected] \n";
$header .= "MIME-Version: 1.0 \n";
$header .= "Content-Type: text/html; charset=iso-8859-1; type=\"text/html\" \n";
mail($email,$betreff,$mailbody,$header)
and it works fine.
Upvotes: 1
Reputation: 68
You need a mail server, that you may not have on your dev environment.
mail() and PHPMailer simply hand over your e-mail to a mail server, which will then proceed to actually send it to it's destination.
If you don't have a mail server available, no matter how good your code is, it simply won't do anything. Check for any return codes or exceptions that you may be missing (I'm not sure how PHPMailer indicates something went wrong, mail() does it by return code),
I never really used PHPMailer, but it seems to me that you're not setting an external server to relay the message, which means PHPMailer will default to the local machine.
A mail server isn't something you just install and configure in a couple of minutes, which I believe your local machine doesn't have.
So, here's what I think is happening:
1) You didn't set an external server, PHPMailer defaults to the local server.
2) You don't have a local mail server, which makes PHPMailer fail.
3) You're missing/ignoring $mail->Send()'s return code / thrown exception, which should tell you something went wrong.
Upvotes: 0