I have the following code which sets up the SMTP server:
ini_set("send_from", "[email protected]");
ini_set("SMTP", "smtp.gmail.com");
and i create a simple mail in this way:
mail("[email protected]", "A subject", "My message for you", "From: TEST");
When I run this code, it fails to send mail to Yahoo e.g. [email protected]. But when i use any Gmail mail address as the first argument, it works.
What's wrong ?
In thi case you dont auth (user name passwort) and dont usw tls. This wont be accepted.
Better use this:
XAMPP Sendmail using Gmail account
or an framework to send emails via smtp like
http://framework.zend.com/manual/1.12/en/zend.mail.sending.html
Here a code example
http://framework.zend.com/downloads/latest#ZF1
require('Zend/Mail.php');
$config = array(
'ssl' => 'tls',
'port' => 587,
'auth' => 'login',
'username' => '[email protected]',
'password' => 'password'
);
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Zend_Mail::setDefaultTransport($smtpConnection);
Zend_Mail::setDefaultFrom('[email protected]', 'Your real name');
$mail = new Zend_Mail();
$mail->addTo('[email protected]', 'Test');
$mail->setSubject(
'Demonstration - Sending Mails per SMTP Connection'
);
$mail->setBodyText('...Your message here...');
$mail->send($smtpConnection);