0

Hi I have used sendgrid to send emails in the past and am using it as a reset password on an app currently. I want to use it for another app also. My AWS has a new instance for the second app. I have copied the sendmail.ini from my first instance and the php.ini and I am using basically the same code for sending emails in my php files. The first is working, the second isn't. Code below:

$subject = "Don't be stuck for a password!" ;
$Emessage = wordwrap("<html><body>Please click the link below to reset your password. <br><br> <a href=http://xxx.xxx.xx/resetPassword.php?AuthCode=".$Token."&email=".$email."&userid=".$userid." />Reset Password</a><br><br> Thanks, <br></body></html>", 70, "\r\n");
$from= "xxx@xxx.com";
$from_name="xxx Ltd.";
$headers = "Date: ". date("r") ."\r\n". "From: $from_name <$from>\r\n";

$headers  .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


//echo $message;
$mailSent= mail($email, $subject, $Emessage, $headers);
if (!$mailSent){
    //$reset= error_get_last();
    $reset='Not OK';
}

Note the mailSent is returning true. It must be some config issue. Also, I am running the same version of xampp on both instances.

My sendmail.ini is as follow:

[sendmail]

smtp_server=smtp.sendgrid.net
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=xxx
auth_password=yyy
force_sender=xxx@xxx.com

and my php.ini has the following in the [mail function]:

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" - t"
AnFi
  • 10,493
  • 3
  • 23
  • 47
user2363025
  • 6,365
  • 19
  • 48
  • 89
  • How exactly is it *not working*? E-Mails are not send? Error Messages? – Andresch Serj Apr 29 '14 at 09:26
  • @Andresch Serj emails aren't sending but I'm not gettting any error messages – user2363025 Apr 29 '14 at 09:29
  • Do you check the `$reset` variable after your `if(!$mailSent` check? How do you expect to see the error? Did you check if the mail ends up in your SPAM/Junk Folder? – Andresch Serj Apr 29 '14 at 09:30
  • In my app I am checking the reset variable and it's returning OK. It would return Not OK, if it got in this if- if (!$mailSent){ //$reset= error_get_last(); $reset='Not OK'; } – user2363025 Apr 29 '14 at 09:32
  • @Andresch Serj I am returning it in the browser also, just don't have that part of the code here – user2363025 Apr 29 '14 at 09:33
  • still doesn't answer if the mail ends up in SPAM/Junk. Also, what are your error reporting settings in your php.ini? Does the sendmail.exe exist in that folder on the system where the mail is not send? Did you try sending the exact same testmail from both systems/solutions and see if it arrives on any of them? – Andresch Serj Apr 29 '14 at 09:38
  • 1
    @Andresch Serj it's not in the spam/junk. In each file where I am sending an email, I have the follwing line of code: ini_set('display_errors',1); - that's all I have on the error reporting front. In my send grid account, it isn't in the activity list either. The sendmail.exe exists. I did try sending the exact message. It is sending on one and not the other. – user2363025 Apr 29 '14 at 09:41

2 Answers2

0

Since the same code is working on one instance and not the other, if we assume the instances are exactly the same, it must be external to your instance. AWS has an initial outbound email limit, so it's possible you're hitting that, but it's been lifted on your other instance.

One way to get around this, is to send via SendGrid's Web API (which is not limited on AWS [as it sends over port 80]).

You won't be able to send using the mail function, however, we have a PHP Library to send email that makes it easy enough to do.

Nick Q.
  • 3,947
  • 2
  • 23
  • 37
  • The only difference is the first is micro and the new second one is medium. I haven't successfully sent even one email from the second instance but there's still a chance I'm hitting the limit?? – user2363025 Apr 29 '14 at 09:54
  • Q also I just tried using the basic sample code from here https://sendgrid.com/docs/Code_Examples/php.html and it isn't even printing a response. Do I need to download the library first? – user2363025 Apr 29 '14 at 09:56
  • Q based on experience is there any other file I would have needed to change to get it working the php mail function way? I may have a different config somewhere else outside the php.ini and sendmail.ini files? – user2363025 Apr 29 '14 at 10:10
  • The [SendGrid PHP Code Sample](https://sendgrid.com/docs/Code_Examples/php.html) does not use our library. However, I'd recommend you do use the library as it tends to be a little easier than raw `curl`, to use it, first [install it](https://github.com/sendgrid/sendgrid-php#installation) and then follow the [usage instructions](https://github.com/sendgrid/sendgrid-php#usage). – Nick Q. Apr 29 '14 at 10:11
  • Q thanks for thee help. I am wondering though is there just some issue with my instance sending emails since the php mail function and the raw curl didn't work. I will look into your library anyway – user2363025 Apr 29 '14 at 10:20
0

Turns out I made the rookie mistake of not restarting my Apache! That was all that was wrong!

user2363025
  • 6,365
  • 19
  • 48
  • 89