Page 1 of 2
mail() function
Posted: Tue Mar 31, 2009 10:13 am
by matt1234
When I run a page with the mail() function, I get "Recipient names must be specified"
This is just a test page, btw...
Code: Select all
echo "K.";
$msg = "Message body";
$msg. = "Continued \n";
$recip = "<webmaster@mywebsite.com>";
$subject = "Test E-mail";
$mailheader = "From: Our E-mail Account <email@mywebsite.com> \n";
$mailheader .= "Reply-To: <email@mywebsite.com> \n";
$mail($recip,$subject,$msg,$mailheader);
Re: mail() function
Posted: Tue Mar 31, 2009 12:27 pm
by Christopher
I think $recip should be either "Webmaster <
webmaster@mywebsite.com>" or just "
webmaster@mywebsite.com"
Re: mail() function
Posted: Tue Mar 31, 2009 1:42 pm
by matt1234
No such luck, unfortunately
Re: mail() function
Posted: Tue Mar 31, 2009 2:12 pm
by becky-atlanta
Code: Select all
# $mail($recip,$subject,$msg,$mailheader);
I think $mail does not need the $. I have seen example with @, i.e. @mail(...).
Re: mail() function
Posted: Tue Mar 31, 2009 2:34 pm
by matt1234
Sorry, you're right about that. I retyped it on the forum but my actual code doesn't have the "$"
Re: mail() function
Posted: Tue Mar 31, 2009 2:52 pm
by becky-atlanta
These are examples from
http://us3.php.net/function.mail:
----------------------------------------------------------------------------
to
Receiver, or receivers of the mail.
The formatting of this string must comply with » RFC 2822. Some examples are:
*
user@example.com
*
user@example.com,
anotheruser@example.com
* User <
user@example.com>
* User <
user@example.com>, Another User <
anotheruser@example.com>
-------------------------------------------------------------------------------
I used them before and they worked.
Re: mail() function
Posted: Tue Mar 31, 2009 4:10 pm
by Apollo
I think the problem is here:
Use either
"webmaster@mywebsite.com" or
"Matt <webmaster@mywebsite.com>". See RFC specs above.
Re: mail() function
Posted: Tue Mar 31, 2009 5:04 pm
by matt1234
Code: Select all
<?php
// The message
session_start();
$message = "Line 1\nLine 2\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
echo "UM....";
// Send
if (mail('Webmaster <webmaster@mysite.com>', 'My Subject', $message)) {
echo 'E-mail sent.';
}
else {
echo "uh oh!";
}
?>
And I get:
UM....Recipient names must be specified E-mail sent.
I put the echo 'UM...' there just because if I don't echo something while I'm testing it and having this problem, it gives me an internal 500 error.
I took this code straight from the PHP site other than the echos, the "if", and the session_start(); I'm at a loss here.
Re: mail() function
Posted: Tue Mar 31, 2009 6:08 pm
by Apollo
On what kind of server are you running this? Does it have an SMTP server installed? Does phpinfo() reveal anything?
Re: mail() function
Posted: Tue Mar 31, 2009 8:51 pm
by matt1234
I'm on a LAMP server
There's a SMTP
What would you like to know what the phpinfo says that would help me or help you in your helping me?
Re: mail() function
Posted: Wed Apr 01, 2009 3:06 am
by Apollo
No I was hoping to get some info about the SMTP. But if you say it's installed, it will probably be OK.
Does it make a difference if you try and use a dedicated mail class, like
phpmailer ?
Re: mail() function
Posted: Thu Apr 02, 2009 6:11 pm
by matt1234
Mailer Error: The following From address failed:
email@mywebsite.com
Re: mail() function
Posted: Thu Apr 02, 2009 7:06 pm
by Chris Corbyn
Is the address hand-coded, or pulled from a database? Check to make sure there's no whitespace either side of it (trim() it).
Re: mail() function
Posted: Thu Apr 02, 2009 7:59 pm
by McInfo
This is probably unrelated to the problem at hand, but according to
RFC 2822:
Messages are divided into lines of characters. A line is a series of
characters that is delimited with the two characters carriage-return
and line-feed; that is, the carriage return (CR) character (ASCII
value 13) followed immediately by the line feed (LF) character (ASCII
value 10).
This applies to the lines in your custom header ($mailheader). Your header lines should end with:
Edit: This post was recovered from search engine cache.
Re: mail() function
Posted: Fri Apr 03, 2009 1:28 am
by matt1234
Address is hand-coded
As far as the mail header goes, thanks for the tip - I'll remember that, but the error mentions the recipient names. I don't know why it says name"s".