473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with headers using mail() function

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
2 1653
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: >>Shailesh | last post by:
hi, my script(IMAP email client) is sending mail using imap_mail() function. imap_mail($To, $Subject, $Body, $headers); $headers = "From: <$From>\n"; $headers .= "X-Sender:...
4
by: splicemix | last post by:
Hi all, I have recently set up a Drupal website. I am a beginner. My shared host server does not allow nobody@localhost to send emails, and prevents access to php.ini, so I spent some time...
7
by: Ramon | last post by:
Hello, when I send an email using the mail() function, I get a Runtime Notice: date() : It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ...
2
by: MJ | last post by:
I use the following code to send mails using php usinf PEAR package. When I run this code from command line using the command "php automaticMail.php" the code works fine. But when i run this...
4
by: sravani1 | last post by:
Hi, I run the following code error will occure. Plz tell that what mistake i have done <?php // multiple recipients $to = 'sravani_409@yahoo.com' . ', '; // note the comma $to .=...
4
by: pavani1 | last post by:
hi, i used the below code i got the message field with the html tags. plz tell that what's the problem in my code. <?php $to ='$_POST"; $subject = "Site Registration Confirmation";...
3
by: swethak | last post by:
hi, i run the below code i got the below error when i run in my local system.And i placed same program in website it works fine.plz tell that what's the mistake in that. <?php $to...
6
by: Call Me Tom | last post by:
The following simple script receives data from a form and sends me an email. It works fine on my testing machine (xampp for windows). However, when I upload it to my web host, the script processes...
2
by: urbanedge | last post by:
I've uploaded a site to a new server and now the headers in the mail function are not working to send the required email response. This is a newly acquired site and my php knowledge is at the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.