0

I know this question has many answers on this website but there is no answer worked for me. So please help me in this ...

I'm trying to send a message in php mail function

And this is index.php

<?php
$to = "test@gmail.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: my gmail ID@gmail.com";
try{

  if(mail($to, $subject, $txt, $headers))
    echo "email has been sent successfully";
  else
    echo "Unknown Error";
}catch(Exception $s){
  echo $s->getMessage();
}
 ?>

This is php.ini

[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my sender ID@gmail.com  
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"   
mail.add_x_header=On    
extension=php_openssl.dll

And this is sendmail.ini

smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=auto
error_logfile=error.log
auth_username=my sender ID@gmail.com
auth_password= my ID password
force_sender=my sender ID@gmail.com

NOTE: XAMPP v 3.2.2

NOTE: PHP v 7.0.13

u_mulder
  • 54,101
  • 5
  • 48
  • 64
B.Nabeih
  • 151
  • 1
  • 12
  • Are you able to send a message from the command line using sendmail? – raphael75 Dec 14 '16 at 16:48
  • 1
    Can you elaborate on the problem? What exactly isn't working? Is there some kind of error appearing? Does it say the email was sent succesfully, but it never received? Did you get a mail from gmail postmaster about this issue? We need more info to give you a better answer to your problem than just guessing. – icecub Dec 14 '16 at 16:49
  • mail function returns false so according my code in index.php it says Unknown Error @icecub – B.Nabeih Dec 14 '16 at 16:52
  • Great! So that means you can find more info in the `error.log` file. You should open that one up in a text editor and scroll all the way down. There you'll see more info about what's going on. – icecub Dec 14 '16 at 16:55
  • @raphael75 in fact i don't know to do it from command line!! – B.Nabeih Dec 14 '16 at 16:55
  • If the file is to complicated for you to understand, feel free to upload it somewhere and give me a link to it. I'll check it out for you and, if nessesary, edit your question with any relevant info. – icecub Dec 14 '16 at 16:59
  • @icecub Sorry, i understand nothing from there... – B.Nabeih Dec 14 '16 at 17:01
  • As I said: Upload it somewhere. Or email it to me as an attachment. You can find my email on my profile here. I'll check it out. – icecub Dec 14 '16 at 17:03
  • @icecub i have sent you a message .. thanks for your interesting :) – B.Nabeih Dec 14 '16 at 17:09
  • The logs tell me you're getting SSL warnings continuesly `www.example.com:443:0 server certificate does NOT include an ID which matches the server name`. I'm not exactly sure what this means, but perhaps there's a misconfiguration somewhere where you're trying to connect to example.com? – icecub Dec 14 '16 at 17:17
  • There aren't any other interesting errors in there though. Perhaps you should considder downloading and using the [PHPMailer](https://github.com/Synchro/PHPMailer) library instead. It works perfectly with SMTP servers and can return you meaningfull errors in case something goes wrong. – icecub Dec 14 '16 at 17:21
  • Thanks you .. it worked finally @icecub – B.Nabeih Dec 14 '16 at 18:08

0 Answers0