Reputation: 1668
hi i use to send a mail in contact form using ajax passing values to php file called test.php all are working fine.
code in test.php
if(mail($to,$subject,$message,$headers))
{
echo "mail sent";
}
else
{
echo "no mail sent";
}
Ajax working fine when the mail sent i'm getting mail sent
message when the mail is not sent i should get no mail sent
. but i'm not getting that alone i'm getting bunch of error code
<br />
<font size='1'><table class='xdebug-error xe-warning' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: mail(): SMTP server response: 551 User not local. We don't relay in E:\wamp1\wamp\www \test.php on line <i>42</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0007</td><td bgcolor='#eeeeec' align='right'>275552</td><td bgcolor='#eeeeec'>{main}( )</td><td title='E:\wamp1\wamp\www\wp_twentythirteen\wp-admin\admin-ajax.php' bgcolor='#eeeeec'>..\admin-ajax.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.2273</td><td bgcolor='#eeeeec' align='right'>20765536</td><td bgcolor='#eeeeec'>do_action( )</td><td title='E:\wamp1\wamp\www\wp_twentythirteen\wp-admin\admin-ajax.php' bgcolor='#eeeeec'>..\admin-ajax.php<b>:</b>72</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.2273</td><td bgcolor='#eeeeec' align='right'>20767104</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.call-user-func-array' target='_new'>call_user_func_array</a>
( )</td><td title='E:\wamp1\wamp\www\wp_twentythirteen\wp-includes\plugin.php' bgcolor='#eeeeec'>..\plugin.php<b>:</b>406</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.2273</td><td bgcolor='#eeeeec' align='right'>20767136</td><td bgcolor='#eeeeec'>contact_ajax( )</td><td title='E:\wamp1\wamp\www\wp_twentythirteen\wp-includes\plugin.php' bgcolor='#eeeeec'>..\plugin.php<b>:</b>406</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>5</td><td bgcolor='#eeeeec' align='center'>0.2273</td><td bgcolor='#eeeeec' align='right'>20767312</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.mail' target='_new'>mail</a>
( )</td><td title='E:\wamp1\wamp\www \test.php' bgcolor='#eeeeec'>..\test.php<b>:</b>42</td></tr>
</table></font>
"no mail sent"
In last line am getting this no mail sent
message. Why is these happening.i want no mail sent message alone. can anybody help
Upvotes: 0
Views: 225
Reputation: 2764
If you are on localhost (your comptuer) and you are developing this script you can either setup a mail server or use a debug mail function as a wrapper for mail() for your script, where the function accepts all of the same arguments as mail() but does not actually call mail() (instead, it could print the info to the screen or a text file for example).
Then, when you are ready to put the system online, you could modify the function to call mail().
The mail server needs a user login and password for SMTP authentication.
Which means you should contact your webhost as they should provide a working configuration by default (or instructions to obtain such a configuration).
Alternatively you could use PEAR to sort out your problems.
Upvotes: 0
Reputation: 24374
Try it with rather try
and catch
try {
mail($to,$subject,$message,$headers);
echo "mail sent";
} catch (Exception $e) {
$error = 'Caught exception: '. $e->getMessage();
error_log($error);
echo "no mail sent";
}
Upvotes: 0
Reputation: 1158
yes, it seems the user isnot allowed to send the email. if you read the error properly it says the same.
Warning: mail(): SMTP server response: 551 User not local. We don't relay in E:\wamp1\wamp\www \test.php on line 42
Read this post @ http://www.webmaster-talk.com/php-forum/60248-smtp-server-response-551-a.html This should get you going.
Also, adding '@' before the mail function as suggested by many would only ignores the warning. It would not make email function work if a email server isnot set up properly.
Upvotes: 2
Reputation: 9034
Hide that error message using @
in front mail function:
if (@mail($to, $subject, $message, $headers))
Upvotes: 0