This is the first time I am using the mail function. I tried to send a mail using this and the code tells me it's "successfully sent", but I didn't receive any mail. I'm confused reading lots of articles on this. Please help me.
<?php
if(isset($_POST['author'])&& isset($_POST['subject'])&& isset($_POST['text'])) {
//Email
$email_to = "lucy@yahoo.com";
$email_subject = "Query From HYPERMARKETS";
$name = $_POST['author']; // required
$sub = $_POST['subject']; // required
$comments = $_POST['text']; // required
echo "POST:".$name.$sub.$comments;
$error_message = "";
$string_exp = "^[a-z .'-]+$";
if(!strcmp($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 5) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
echo ("<center><table border=1 cellspacing=5 cellpadding=5><tr><th>$error_message</th></tr></table></center>");
}
$email_message = "Form details below.\n\n";
$email_message .= "Name: ".$name."\n";
$email_message .= "Subject: ".$sub."\n";
$email_message .= "Comments: ".$comments."\n";
// create email headers
$headers = "From: mary@yahoo.com \r\n Reply-To: mary@yahoo.com \r\n" ;
if(@mail($email_to, $email_subject, $email_message, $headers))
echo "<center><table border=1 cellspacing=5 cellpadding=5><tr><th>MESSAGE SENT SUCCESSFULLY</th></tr></table></center>";
else
echo "<center><table border=1 cellspacing=5 cellpadding=5><tr><th>MESSAGE NOT SENT</th></tr></table></center>";
}
else
echo ("<center><table border=1 cellspacing=5 cellpadding=5><tr><th>FILL ALL THE FIELDS..!!</th></tr></table></center>");
?>
Hey I have configured my php.ini file as
[mail function]
sendmail_from = postmaster@localhost
SMTP = localhost
smtp_port = 25
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
It still doesnt work.
First, I would make sure that port 25 is open. Determine the public IP address of the server by connecting to WhatsMyIP.org (from the same internet connection that the server uses) then try the following from the command line:
(replace xxx.xxx.xxx.xxx with the IP from WhatsMyIP.org)
If you can connect, then this answer isn't for you. Sorry.
If not, check all of your local firewall settings to make sure that port 25 is open on your end. Port 25 may also be blocked by the ISP. It turns out that some (maybe most) ISPs block port 25 by default to prevent spam.
Misconfigured email servers are easily compromised and used in spam botnets. I had to call Comcast and jump through hoops to get them to unblock port 25 before I could get my home email server working. (Comcast forum post about port 25).
If that doesn't get you going, I'd take another look at the email server configuration.
did you ever send mails on this server? if not:
you have to configure
mail function
section in php.ini.First of all you have to have SMTP support for send&receive e-mails. Second, you have to configure
SMTP
andsmtp_port
values in php.ini file.Disclosure: I'm one of the developers behind AlphaMail
Since you have no error to go on, it's not that easy to say what the issue is here. I would therefore recommend that to manually try and connect to the SMTP-server from your server and send the email manually. This way you'll have the error in hand instead of second-guessing.
If you don't want to do this, and just want it to "work" I would recommend that you use a Transactional Email Service such as:
Why?
If you choose to go with AlphaMail you could use the AlphaMail PHP-client.
Example:
Another advantage with AlphaMail is that you can edit your templates directly in the AlphaMail Dashboard, and you can format your emails using the Comlang template language.
Some hosting requires the extra parameter for mail. It could possibly be that.
It's not very common, but I have had to deal with it, and it took me ages to diagnose, so thought I would share it just in case.
mail() doesn't actually send mail. It merely submits the message you've generated to the host system's mail subsystem to handle the sending. A result of true indicates that the mail sending subsystem accepted the message as valid. It doesn't indicate that the message was sent.
You'll need to look at your mail spool to see if the messages are in there awaiting delivery, and at your system's mail log to see if it is generating errors when it tries to send your PHP-generated messages.
Even if the message has been successfully sent, it doesn't mean it will be received. It may be caught by a spam filter, or rejected by a server, or just plain sent to the wrong address. It may have been delivered and ended up being marked as junk mail by the receiver's e-mail client. Any number of things can prevent a message being sent, a true response from mail is no indication that it was sent successfully.