MAIL ()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
goldberg
Forum Newbie
Posts: 3
Joined: Fri Jan 04, 2008 8:15 am
Location: Baltimore, MD

MAIL ()

Post by goldberg »

Hi I am having some problems using the mail function with a form. I am getting this error message:

Warning: mail() [function.mail]: SMTP server response: 501 unacceptable mail address in ...


Here is my code($msg is defined elsewhere)

Code: Select all

$e =$_POST[email];

$headers="From: ".$e."\n"
    . "Content-Type: text/plain; charset=$charset; format=flowed\n"
    . "MIME-Version: 1.0\n"
    . "Content-Transfer-Encoding: 8bit\n"
    . "X-Mailer: PHP\n";


mail("theiblis11@gmail.com","funding questionare",$msg,$headers);
and also I know the $e var is working because I echo it and it looks fine.
I don't kow whats wrong please help!

Thanks - Goldberg :?:
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Have you tried using \r\n on the headers section as stated in the manual (rather than just \n)?
additional_headers (optional)
String to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n).
You are also in danger of being used by spammers for header injection if you use $_POST['email'] in the headers without making sure it just contains an email address....
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Scrub that - it works for me with \n on a Linux PHP installation.

I googled "501 unacceptable mail address" - the server at the gmail end doesn't like your From address.

Why not try the "from" address to be one from your domain and then have a cc: to $e
Answer
Some SMTP servers require that the FROM user be registered with the domain.
Last edited by andym01480 on Fri Jan 04, 2008 4:42 pm, edited 1 time in total.
goldberg
Forum Newbie
Posts: 3
Joined: Fri Jan 04, 2008 8:15 am
Location: Baltimore, MD

Post by goldberg »

Thanks, but thats not it i've tried several diffrent email addresses, and r\n and none of that helps. Thanks tho. :cry:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you tried Swift Mailer? Even for "simple" stuff, it's quite helpful.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

Well, lets narrow this problem down. Start by sending the email without the headers.
Post Reply