You must have SMTP Server, so you can send mails
Alternative solutions is to use externals one, like gmail for example
First you should have a valid gmail credetials, after that go to php.ini and configure it as follow :
[mail function]
SMTP = ssl://smtp.gmail.com
smtp_port = 465
username = YOUR_GOOGLE_USERNAME
password = YOUR_GOOGLE_PASSWORD
Restart your web server and try with the classic php mail() function
Here is my yml SMTP Server configuration that i have used for a symfony project :
parameters:
mailer_transport: gmail
mailer_host : 127.0.0.1
mailer_user : [email protected]
mailer_password : ***my_gmail_password_secret***
locale : en
You can setup your own local SMTP Server local SMTP Server
__EDIT__
Try with PHPMailer : PHPMailer - A full-featured email creation
And the good thing with it, that it will let you debug what is causing troubles with sending mails using gmail smtp server
First thing : are you behind proxy ? if it's the case, you have to configure the HTTP_PROXY/HTTPS_PROXY
environment variables
You can find useful documentations here and here
Now, you can create a php test script that you can launch directly via commands line or using a web server
<?php
require_once ('PHPMailer-master/class.phpmailer.php');
require_once ('PHPMailer-master/class.smtp.php');
$mail = new PHPMailer();
$body = "<h1> Sending HTML Mails using gmail</h1><p>it's great !!</p>";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "YOUR_GMAIL_ACCOUNT" ; // GMAIL username
$mail->Password = 'YOUR_GMAIL_PASSWORD' ; // GMAIL password
$mail->SetFrom('[email protected]', 'Anis Halayem');
$mail->Subject = "Test Send Mails";
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address, "USER NAME");
// $mail->AddAttachment("images/phpmailer.gif"); // attachment
// $mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
echo "Message sent!";
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…