1

I just need a really simple email to be sent when a user submits a form on my website. (I've looked into using PHPMailer, but have failed to have it actually send an email. I've kind of given up on it because it really is more complex than I need.) In my form handling .php file, I have this code at the end:

if (!mail($_POST['email'], "Registration - Your New Password", "Your password is: ".$pass)) 
echo "didn't send email";
else echo "email sent";

I get a message saying "email sent," but I never receive any emails when I put in my personal email address. Does anyone know why this code seems to be interpreted correctly but yet it doesn't send emails?

Here are some steps I took before testing the above mail():
1) I installed ssmtp
2) I configured /etc/ssmtp/ssmtp.conf so that it looks like this:

    root=postmaster
    root=myemail@gmail.com
    mailhub=smtp.gmail.com:587
    UseSTARTTLS=YES
    AuthUser=myemail
    AuthPass=mypass

    hostname=mywebsite.com

    FromLineOverride=NO

3) In /etc/php5/apache2/php.ini and in /etc/php5/cli/php.ini I set the line starting sendmail_path to sendmail_path = /usr/sbin/ssmtp -t
4) I've restarted apache2: "sudo service apache2 restart"

Note: I've seen lots of other posts on this topic on SO, but haven't really found any solutions in those questions. Perhaps I missed the solution in these other posts, so if that's a case, could you give me the link to that other post?

reubonwry
  • 317
  • 4
  • 15
  • 1
    See also http://stackoverflow.com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail. Configuring SSMTP would be on-topic for Serverfault. – mario Nov 22 '15 at 22:29
  • If you're passing raw `$_POST` variables into the `mail()` function, you stand a risk of being hacked. Make sure you properly sanitise your variables, particularly email addresses. – Spudley Nov 22 '15 at 23:19
  • I honestly don't get what you've got against phpMailer -- it's about as simple as it gets. Just `include` the file, and write ten lines of code, and you've got a robust email system that sanitises your input data and can mail out directly to gmail, without you needing to configure ssmtp at all. – Spudley Nov 22 '15 at 23:21
  • The problem I've had with PHPMailer is that I'm running into the same problem -- I get it to have return true when it sends mail, but I never receive emails. I would love it if it worked. I've tried using several examples, including ones from the GitHub page and from the examples folder in PHPMailer. However, all the examples have been closer to 50 lines of code. Do you have a particular example set of PHPMailer code that you'd recommend for sending from a gmail account? – reubonwry Nov 24 '15 at 20:22

0 Answers0