0

For some reason I am getting a false value from this function. I will provide all neccessary files for you to help me.

<?php


$to = "emailsendingtoo@mail.com";
$from = "From: emailsendingfrom@mail.com";
$subject = "Hi";
$message = "Hello How are you doing today";

if(mail($to,$subject,$message,$from)){
  echo "mail sent today";
}elseif (mail($to,$subject,$message,$from) === false) {
echo "dudududuududu";
}else {
  echo "nothing";
}

 ?>

That is my function that I am using to try and send mail. Here are my php.ini file settings and my sendmail.ini settings.

php.ini settings:

SMTP =smtp.gmail.com
smtp_port =587
sendmail_from =t-----------@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini settings:

smtp_server=smtp.gmail.com
smtp_port=587
auth_username= t-----------@gmail.com
auth_password= -----------
NewbieCoder
  • 111
  • 4
  • 15
  • Try to take a look to the apache / php (i assume you're using apache) error logs. I don't know if sendmail itself has an error log, you can also try to find it. – Eduardo Escobar Dec 06 '15 at 23:53
  • @EduardoEscobar so im going to xampp control panel and going to logs and then Apache (error.log)? – NewbieCoder Dec 06 '15 at 23:59
  • That's right. Enabling error reporting / log could be useful too, add `ini_set('display_errors', 1);` and `error_reporting(E_ALL);` at the beginning of your PHP script – Eduardo Escobar Dec 07 '15 at 00:06
  • [Sun Dec 06 18:05:48.765308 2015] [mpm_winnt:notice] [pid 109944:tid 560] AH00354: Child: Starting 150 worker threads. this was the last error logged. – NewbieCoder Dec 07 '15 at 00:09
  • Well, that's just as useful as nothing. – Eduardo Escobar Dec 07 '15 at 00:10
  • I saw somewhere that if you receive false then its a server problem, but I thought I got everything right. – NewbieCoder Dec 07 '15 at 00:11
  • Possible duplicate of [PHP mail form doesn't complete sending e-mail](http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – Qirel Dec 07 '15 at 00:11
  • Well I looked at that one and the false options he gives make 0 since to me =/ – NewbieCoder Dec 07 '15 at 00:17
  • I went to the access logs and it is logging this : ::1 - - [06/Dec/2015:18:22:53 -0600] "GET /Mail%20Test/ HTTP/1.1" 200 13 "http://localhost/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36" – NewbieCoder Dec 07 '15 at 00:24
  • Just read through that post, it holds all solutions :-) There are many reasons it could fail. – Qirel Dec 07 '15 at 00:24
  • The code looks good to me, most likely it's a server-setting thing. Read *Make sure your Web host supports sending email* and below in that post I linked to. – Qirel Dec 07 '15 at 00:34
  • Okay he comments that maybe I do not have a email server set up and I sent it to multiple different emails, made sure my header had no syntax errors, etc.. He said you could use mercury , but I do not know what that is. – NewbieCoder Dec 07 '15 at 00:40
  • @Oirel I went [here](http://stackoverflow.com/questions/15965376/how-to-configure-xampp-to-send-mail-from-localhost) and made sure everything was exactly like his and still nothing. – NewbieCoder Dec 07 '15 at 01:09
  • @EduardoEscobar I just found out that the error text were being sent to my sendemail folder. In the error.log text it says this: 15/12/06 19:07:15 : Connection Closed Gracefully.. It just keeps repeating that over and over. – NewbieCoder Dec 07 '15 at 01:17
  • Create add a call to phpinfo() at the top of your page. Look through it & verify that the mail settings are being picked up. Also check your path to sendmail – Rob G Dec 07 '15 at 08:33

1 Answers1

0

The last parameter to mail() is "additional headers", so it should be ended with \r\n. See example #2 at http://php.net/manual/en/function.mail.php

Try:

$from = "From: emailsendingfrom@mai.com\r\n";
Rob G
  • 592
  • 4
  • 18