Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Problem with headers using mail() function
June 13, 2007, 11:06 am
rate this thread
I know there is lots of information out there and I've taken a look, but
I want to learn how to do this myself. And I'm a beginner here and some
of it I don't understand (so no flames, RTFM or GFGI please ;)
Here's my function:
function send_mail($to_name, $to_email, $from_name, $from_email,
$thedate = date("r", time());
$headers = "X-Mailer: PHPMailProgram/1.0\n";
$headers .= "From: \"".$from_name."\" <".$from_email.">\n";
$headers .= "Date: $thedate\n";
$headers .= "Content-Type: text/plain\n\n";
$from = "\".$from_name."\" <".$from_email.">";
return mail( $from, $subject, $message, $headers);
My problem is that it will never arrive with the "Name" <email address>,
and I can only make it work using email addresses without the names or
the angle brackets around the email addresses. Once I tried printing the
headers and the quotes and angle brackets turned up, but no names or
email addresses. And once an email arrived but with nothing but angle
brackets! (I wonder how that happened? The SMTP server must have
stripped things out perhaps?)
Thanks for your time in helping me with this,
Re: Problem with headers using mail() function
Well, the \n worked fine on both my server and my local machine, but
I've changed everything to \r\n anyway.
Everything now works, strangely enough. I must have a dud server or the
server's sendmail doesn't like names and angle brackets. Running my PHP
mailer on my machine at home works just fine using the Windows SMTP
server, name and angle brackets, no problems at all. Weird.
Thanks for your help.
- » if on allow_url_open is set to off is there a way to override this?
- — Previous thread in » PHP Scripting Forum