473,385 Members | 1,673 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,385 software developers and data experts.

Problem: No headers sent with mail()

Hi,

My hostingprovider just updated to PHP 4.4. Since that time I have problems
using the mail() function in PHP. I can't send headers anymore and my
provider don't know what's wrong.
Here's a sample script:

if (mail("xx*@xxx.com", "test mail", "This is a <B>test</B>!", "From:
yy*@yyy.com (yyy)\r\nContent-type: text/html")) {
print "Sent";
}
else {
print "Not sent";
}
I receive this body-text on xx*@xxx.com:

Content-type: text/html
Message-Id: <20************************@xxx.xxx.com>
Date: Thu, 8 Sep 2005 09:40:02 +0200 (CEST)

This is a <B>test</B>!

Does anybody know what's going wrong?

Regards,
Juul
Sep 8 '05 #1
7 1368
I mean that the headers are not interpreted by the mailserver but printed
as plain text...

Juul

Op Thu, 8 Sep 2005 10:17:58 +0200 schreef Juul:
Content-type: text/html
Message-Id: <20************************@xxx.xxx.com>
Date: Thu, 8 Sep 2005 09:40:02 +0200 (CEST)

Sep 8 '05 #2
Juul wrote:
Hi,

My hostingprovider just updated to PHP 4.4. Since that time I have problems
using the mail() function in PHP. I can't send headers anymore and my
provider don't know what's wrong.
Here's a sample script:

if (mail("xx*@xxx.com", "test mail", "This is a <B>test</B>!", "From:
yy*@yyy.com (yyy)\r\nContent-type: text/html")) {
print "Sent";
}
else {
print "Not sent";
}


Had this code worked before?

Try this modification

<?php

if (mail('t********@example.com', 'Test Mail', 'This is a
<b>test</b>','From: Who Dat <fr*******@example.com>'."\nContent-type:
text/html"))
print 'Sent';
else
print 'Not Sent';

?>

What struck me as a possible problem in your original code was the
'From:' sting. The format "yy*@yyy.com (yyy)" doesn't look right. The
correct way is "Name <em***@address.here>"

Ken

Sep 8 '05 #3
Hi Ken,

The script worked fine till the provider updated PHP. You may use
xx*@xxx.com (xxx) as the From header, that shouldn't be a problem.

The real problem I found was the use of \r\n. I tried to use \n only and it
works fine!

Thank you for your help.

Juul
Sep 8 '05 #4
Hello,

on 09/08/2005 05:17 AM Juul said the following:
My hostingprovider just updated to PHP 4.4. Since that time I have problems
using the mail() function in PHP. I can't send headers anymore and my
provider don't know what's wrong.
Here's a sample script:

if (mail("xx*@xxx.com", "test mail", "This is a <B>test</B>!", "From:
yy*@yyy.com (yyy)\r\nContent-type: text/html")) {
print "Sent";
}
else {
print "Not sent";
}
I receive this body-text on xx*@xxx.com:

Content-type: text/html
Message-Id: <20************************@xxx.xxx.com>
Date: Thu, 8 Sep 2005 09:40:02 +0200 (CEST)

This is a <B>test</B>!

Does anybody know what's going wrong?


Several things seem to be wrong. The line breaks may not be correct. You
should not sent HTML only messages as many mail systems like Hotmail may
simply discard your message. For sending properly compose HTML messages,
you should compose MIME multipart/alternative messaages that include the
HTML part and an alternative text part.

If you don't know how to do that, you may want to try this MIME message
class. Take a look at the test_simple_html_mail_message.php example:

http://www.phpclasses.org/mimemessage
--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Sep 9 '05 #5
Juul wrote:
You may use xx*@xxx.com (xxx) as the From header, that shouldn't be a problem.
Because it gives the impression of working? Sorry, ain't gonna wash
in a technical forum.

I think Ken was right to be suspicious, because afaics

From: fo*@bar.invalid (foo)

is not allowed to be generated under RFC2822.

It is one of the two forms allowed by son-of-RFC1036 though, so you
might find it on Usenet, and that might be where your idea that it
'shouldn't be a problem' comes from.
The real problem I found was the use of \r\n. I tried to use \n only and it
works fine!


What you tried there, what the Manual calls 'a last resort', suggests
the real problem lies with your MTA.

--
Jock
Sep 9 '05 #6
John Dunlop <us*********@john.dunlop.name> wrote:

Juul wrote:
You may use xx*@xxx.com (xxx) as the From header, that shouldn't be a problem.


Because it gives the impression of working? Sorry, ain't gonna wash
in a technical forum.

I think Ken was right to be suspicious, because afaics

From: fo*@bar.invalid (foo)

is not allowed to be generated under RFC2822.


No, this is specifically allowed by RFC2822, although new implementations
are discouraged from using it.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Sep 10 '05 #7
Tim Roberts wrote:
John Dunlop <us*********@john.dunlop.name> wrote:
From: fo*@bar.invalid (foo)

is not allowed to be generated under RFC2822.


No, this is specifically allowed by RFC2822, although new implementations
are discouraged from using it.


from = "From:" mailbox-list CRLF
mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list
mailbox = name-addr / addr-spec

It can't be a name-addr because there are no greater-/less-than
signs, so that leaves:

addr-spec = local-part "@" domain

No room for comments there.

--
Jock
Sep 10 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
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...
20
by: Pete Marsh | last post by:
Wondering if anyone can see an error with this script. I get a server configuration error. THat could mean a module is not being loaded, but maybe there's a syntax error here, can anyone spot it?...
1
by: krishan123456 | last post by:
i have tried to send email with attached doc file but when i receive the mail i find the attached file in encoded text instead of actuall attachment.the code that i used to send an email is given...
1
by: the_ricka | last post by:
Hi all, I'm fairly new to python, but very excited about it's potential. I'm trying to write a simple program that will accept input from a command line and send email. The parameters I used on...
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...
3
by: swethak | last post by:
Hi, i placed the php in windows server 2003 manually , set the path in Environmental variables , and place the php.ini file in windows. Now php works fine in my server sytem.When i write the...
0
Dormilich
by: Dormilich | last post by:
this is a follow-up thread to this one. http://bytes.com/topic/html-css/answers/863662-form-not-submitted-sometimes I figured out that the mail sending class triggers the described error....
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.