-
June 4th, 2008, 12:28 PM
#1
Senior Member
PHP mail function and SMTP 501 error
Hi guys
I have this mail function in PHP
<code>
function send_email ($recipient, $from, $reply_address, $subject, $message){
ini_set('display_errors', '1');
error_reporting(E_ALL);
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'To:$recipient\r\n';
$headers .= 'From:<$from>\r\n';
//$headers .= 'Reply-To:$reply_address\r\n';
if(!mail($recipient, $subject, $message, $headers)){
return 'Mail function failed.';
}
else
{
return 'ok';
}
}
</code>
Whenever I call it it comes up with the next error:
Warning: mail(): SMTP server response: 501 Syntax error in forward path in E:\apache2triad\htdocs\i2card.co.uk\functions\email_function.php on line 15
From what I can understand, I made a mistake in setting up the header, but I am not sure which one is it.
Could someone point me in the right direction please?
Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying
-
June 4th, 2008, 12:51 PM
#2
The "To:" header isn't needed as that's already taken care of by the mail function. It's wrong anyway as it should be "RCPT TO:". "From:" is wrong too, that should be "MAIL FROM:". See RFC 2821 for the correct header syntax.
Oliver's Law:
Experience is something you don't get until just after you need it.
-
June 4th, 2008, 01:43 PM
#3
Senior Member
Originally Posted by SirDice
The "To:" header isn't needed as that's already taken care of by the mail function. It's wrong anyway as it should be "RCPT TO:". "From:" is wrong too, that should be "MAIL FROM:". See RFC 2821 for the correct header syntax.
Thanks for your reply. I will go through the paper now.
Tried the changes you advised, but the error still appears.
Yet the function on top is derived from
<code>
function send_email($email,$format='text',$msg='',$subject='')
}
// send an email to the address $email in the format $format
// with contents $msg and subject $subject
global $fromname, $fromemail, $admin_email;
if($format!='text' && $format!='html')
{
return 'Invalid mail format!';
}
$headers='';
if($format=='html')
{
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
}
$headers .= "To: $email\r\n";
$headers .= "From: WebSite Admin <$admin_email>\r\n";
if(!mail($email, $subject, $msg, $headers))
{
return 'Mail function failed.';
}
else
{
return 'ok';
}
}
</code>
And that one is proven to be working fine on the other system. That is why I'm so confused
It's been ages since I last wrote one of these.
Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying
-
June 4th, 2008, 01:51 PM
#4
Senior Member
Could the fact that email functionality is not propely set up (i.e. sendmail_path),
could that leat to the 501 error appearing?
Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying
-
June 4th, 2008, 02:15 PM
#5
I am absolutely no expert in this area but this does look rather odd:
($email,$format='text',$msg='',$subject='')
Are they the right way round?
-
June 4th, 2008, 02:18 PM
#6
Senior Member
OK, I got the function to work, but the e-mails are not arriving to the test address given.
Any ideas?
The problem was that the test server does not have "sendmail_path" setup
Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying
-
June 4th, 2008, 02:27 PM
#7
Any error or failure messages?
Is the test address set up properly?
-
June 4th, 2008, 02:33 PM
#8
Senior Member
Originally Posted by nihil
Any error or failure messages?
Is the test address set up properly?
There's no error message, and I'm sending it to my hotmail account, so that should work fine.
Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying
-
June 5th, 2008, 12:07 AM
#9
well whats your new set of code?
-
June 5th, 2008, 09:23 AM
#10
Senior Member
Well turns out that the functions was perfectly fine.
The mail function is called by a different one, the second person on the project made some changes to the variables and the function itself, but not in every necessary place, so the email was going through joined with the username
like:
un; nightcat
em; email@server.com
theyd come through as "email@server.comnightcat"
I got it, only when I started printing out the variables one by one
Don\'t post if you\'ve got nothing constructive to say. Flooding is annoying
Similar Threads
-
By ThePreacher in forum Miscellaneous Security Discussions
Replies: 17
Last Post: December 14th, 2006, 09:37 PM
-
By Irongeek in forum The Security Tutorials Forum
Replies: 8
Last Post: April 27th, 2005, 04:44 PM
-
By Vorlin in forum Other Tutorials Forum
Replies: 3
Last Post: June 15th, 2004, 10:25 PM
-
By journy101 in forum Newbie Security Questions
Replies: 1
Last Post: May 1st, 2003, 06:16 AM
-
By Sp1d3r-W0lf in forum The Security Tutorials Forum
Replies: 0
Last Post: December 27th, 2001, 05:31 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|