By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,313 Members | 1,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,313 IT Pros & Developers. It's quick & easy.

Problem with headers using mail() function

P: n/a
Hello,

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,
$subject, $message)
{
$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,

Spartacus
Jun 13 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jun 13, 7:06 am, Spartacus <nos...@nowhere.comwrote:
Hello,

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,
$subject, $message)
{
$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,

Spartacus
First, headers need to be separated by "\r\n", not just "\n". Try
that and see if it works any better.

Jun 13 '07 #2

P: n/a
ZeldorBlat wrote:
On Jun 13, 7:06 am, Spartacus <nos...@nowhere.comwrote:
>Hello,

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,
$subject, $message)
{
$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,

Spartacus

First, headers need to be separated by "\r\n", not just "\n". Try
that and see if it works any better.
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.
Spartacus
Jun 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.