0

I'm trying to send mail to a specific email id from localhost.

I've read this and this plus some other posts, but that didn't solve my problem.

Right now I've the following configuration:

PHP.ini

[mail function]
; *For Win32 only*.
; http://php.net/smtp
SMTP=smtp.gmail.com
; http://php.net/smtp-port
smtp_port=587
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = mypersonal@gmail.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

SENDMAIL.ini

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=mypersonal@gmail.com
auth_password=my above email password
force_sender=mypersonal@gmail.com

**PHP CODE IS **

$to = "someFriend@gmail.com";
$subject = "HTML email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <mypersonal@gmail.com>' . "\r\n";


$check = mail($to,$subject,$message,$headers);
if($check == true){
    echo "successfully mail Sent";
}
else{
    echo "Email sending Failed";
}

I get Email sending failed, is anything wrong with this configuration or code ? I've also allowed my Gmail to less secure apps

I'm also confused about where to put my own gmail id from where the mails would be sending to others.

Please help ! Thanks

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Nprogrammer
  • 13
  • 3
  • 7
  • There are some thing like I mentioned , what to put instead of these or leave them as it is e.g force_sender=@gmail.com like the angular brackets etc, should I use my own gmail id ? @Dave – Nprogrammer Mar 14 '19 at 16:18
  • or please tell me about how can I see my errors if any there, because I don't know where is the problem, the link you've mentioned, I've visited that a number of time before. @RiggsFolly – Nprogrammer Mar 14 '19 at 16:29
  • Ok, OK! Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Mar 14 '19 at 16:30
  • Ok,I will.Can you please have a look at the code above, should it work perfectly fine or there is something missing ? @RiggsFolly what do you think ? – Nprogrammer Mar 14 '19 at 16:34
  • In `sendmail.ini` add `error_logfile=sendmail_error.log` and `debug_logfile=sendmail_debug.log` or have a quick read of [The manual](http://php.net/manual/en/ref.mail.php) – RiggsFolly Mar 14 '19 at 16:35
  • Nothing has happened, I added error reporting, still having the previous result – Nprogrammer Mar 14 '19 at 16:50

1 Answers1

0

Gmail does not allow that by default. Check in your google account settings and allow access to less secure apps. Or generate app specific password and use it here.

Vigas Deep
  • 82
  • 8