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\'
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
and smtp_port
values in php.ini file.
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:
telnet xxx.xxx.xxx.xxx 25
(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.
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.
Some hosting requires the extra parameter for mail. It could possibly be that.
$ffrom = '-fmary@yahoo.com';
if(@mail($email_to, $email_subject, $email_message, $headers, $ffrom));
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.
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:
include_once("comfirm.alphamail.client/emailservice.class.php");
$email_service = AlphaMailEmailService::create()
->setServiceUrl("http://api.amail.io/v1")
->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");
$person = new stdClass();
$person->userId = "1234";
$person->firstName = "John";
$person->lastName = "Doe";
$person->dateOfBirth = 1975;
$response = $email_service->queue(EmailMessagePayload::create()
->setProjectId(12345) // Your AlphaMail project (determines template, options, etc)
->setSender(new EmailContact("Sender Company Name", "from@example.com"))
->setReceiver(new EmailContact("Joe Doe", "to@example.org"))
->setBodyObject($person) // Any serializable object
);
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.
<html>
<body>
<b>Name:</b> <# payload.firstName " " payload.lastName #><br>
<b>Date of Birth:</b> <# payload.dateOfBirth #><br>
<# if (payload.userId != null) { #>
<a href="/sign-up">Sign Up Free!</a>
<# } else { #>
<a href="/login?id=<# payload.userId #>">Sign In</a>
<# } #>
</body>
</html>