1

I have the following code which sets up the SMTP server:

ini_set("send_from", "test@gmail.com");
ini_set("SMTP", "smtp.gmail.com");

and i create a simple mail in this way:

mail("test@yahoo.com", "A subject", "My message for you", "From: TEST");

When I run this code, it fails to send mail to Yahoo e.g. some.email@yahoo.com. But when i use any Gmail mail address as the first argument, it works.

What's wrong ?

Praveen Puglia
  • 5,577
  • 5
  • 34
  • 68
Snake Eyes
  • 16,287
  • 34
  • 113
  • 221

2 Answers2

1

To send mail as an authenticated user you should use email authentication methods like SPF, DKIM etc.

Also you need to make sure your domain should point to your IP address and IP address MUST point to same domain. This is called Reverse DNS

Other good practice that prevents mails from going into spam folder are

  1. Make sure you have a unsubscribe link
  2. Make sure the Reply-To header is added and the email used here is a valid email.
  3. Add a Name in the To field. Like First Last <email@example.com>
  4. Add a postal address of the company you are mailing from which must include a phone number.

There was a form to white list email senders IP for yahoo. Now I dont find it. So try the above things, It should work well.

Shiplu Mokaddim
  • 56,364
  • 17
  • 141
  • 187
0

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

Zend Mail Gmail SMTP

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' => 'your_gmail_address@gmail.com',
    'password' => 'password'
);
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);

Zend_Mail::setDefaultTransport($smtpConnection);

Zend_Mail::setDefaultFrom('your_gmail_address@gmail.com', 'Your real name');

$mail = new Zend_Mail();
$mail->addTo('any_address@yahoo.com', 'Test');

$mail->setSubject(
        'Demonstration - Sending Mails per SMTP Connection'
    );

$mail->setBodyText('...Your message here...');

$mail->send($smtpConnection);
Community
  • 1
  • 1
GreenRover
  • 1,486
  • 1
  • 14
  • 33