0

I'm having problems sending a mail through php. I've already set in php.ini SMTP:

SMTP = xx.xxx.xxx.xx
smtp_port = 25

And I'm in php to send an email with the following code:

// Set up parameters
$to = "xpto.87@gmail.com";
$subject = "Title";
$message = "Hello world";

// Send email
$mail = mail($to,$subject,$message);

// Inform the user
if($mail == true)
   echo "send mail";
else
   echo "dont send";

What do I get and always a "dont send", and i dont know why. Anybody can help me please?

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
UZUMAKI
  • 43
  • 1
  • 7
  • Is your SMTP server configured properly? are you trying on your development machine? or Production server? – Muhammad Ummar Mar 18 '13 at 11:02
  • what SMTP you have set..?? gmail??? if yes then PORT must be `587` and use `tls` instead of `ssl` – Dipesh Parmar Mar 18 '13 at 11:04
  • @Ummar Yes, SMTP is correct. The SMTP is on another machine, and not on this machine where the php and Apache. I only restarted apache after modifying the php.ini. Do I have to restart the server? – UZUMAKI Mar 18 '13 at 11:06
  • @DipeshParmar The gmail SMTP is not, is even own a server for such – UZUMAKI Mar 18 '13 at 11:07
  • @UZUMAKI very few servers still use port `25`, `465` with `ssl` or `tls`, `587` without encryption, administrators often block send e-mails from server, use for example [swiftmailer](http://swiftmailer.org/). – mkjasinski Mar 18 '13 at 11:07
  • simply try to send email using same SMTP server from `Outlook`, see if it works? – Muhammad Ummar Mar 18 '13 at 11:08
  • @Ummar Wait. I dont have Outlook install in server. I tried another pc and it worked – UZUMAKI Mar 18 '13 at 11:16
  • Then I would recommend to use `PHPmailer`, it will give you some extended information about error, and it is very easy to use. – Muhammad Ummar Mar 18 '13 at 11:32
  • Try to provide more detailed debug info. http://stackoverflow.com/questions/2896280/debugging-php-mail-and-or-phpmailer seems to provide debug hints. – AnFi Mar 18 '13 at 17:21

1 Answers1

0

I have succesfully sent email from PHP over GMAIL using following code:

$from = "who";
$to = "to";
$subject = "subject";
$host = "ssl://smtp.gmail.com";
$port = 465;
$username = "yourusername";
$password = "yourpass";

$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp',array ('host' => $host,
 'auth' => true,
 'port' => $port,
 'username' => $username,
 'password' => $password));

$mail = $smtp->send($to, $headers, $body);

Tell me if it works in your case.

Piotr Kowalski
  • 338
  • 4
  • 14
  • UZUMAKI wrote that it's not gmail. – mkjasinski Mar 18 '13 at 11:10
  • @mkjasinski Give me error 500 Internet Server. I put my mail in to (mark@gmail.com), username (and my email) and password is the password to access the correct email? What is the body? – UZUMAKI Mar 18 '13 at 11:14
  • @UZUMAKI because `Mail` class isn't part of `PHP`. It must be external library, use [swiftmailer](http://swiftmailer.org/), easy and fast library. – mkjasinski Mar 18 '13 at 11:23