Php mail not sending using ssmpt -


im working on small project of mine , wanted add contact form , did. works fine, except doesn't seem send email.

i've installed ssmpt , configured right:

# # config file ssmtp sendmail # # person gets mail userids < 1000 # make empty disable rewriting. root=postmaster  # place mail goes. actual machine name required no  # mx records consulted. commonly mailhosts named mail.domain.com  mailhub=smtp.gmail.com:587 usestarttls=yes usetls=yes authuser=myemail@gmail.com authpass=mypasdword  # mail seem come from? #rewritedomain=  # full hostname hostname=hidingthisforsecurity  # users allowed set own from: address? # yes - allow user specify own from: address # no - use system generated from: address #fromlineoverride=yes 

i've configured php.ini:

 ; unix only.  may supply arguments (default: "sendmail -t -i").  ; http://php.net/sendmail-path  sendmail_path = /usr/sbin/ssmtp -t 

this code:

 <?php   require 'config.php';   $strcontactemail = "myemail@gmail.com"; //edit email   function senderror($strerr) {          $strmsg = "<center><h2>error: " . $strerr . "</h2></center>";           die($strmsg);  }   $resdbcon= mysqli_connect($strdbhost, $strdbuser, $strdbpass, $strdbname) or senderror('failed connect mysql: ' . mysqli_connect_error());   if (isset($_post['submit'])) {  $strusername = $_post['username'];  $stremail = $_post['email'];  $strsubject = $_post['subject'];  $strmessage = $_post['comments'];   if (!isset($strusername) || !isset($stremail) || !isset($strsubject) || !isset($strmessage)) {      senderror('one or more fields has not been completed, please fill in everything');       }   $strusername = mysqli_real_escape_string($resdbcon, $strusername);  $stremail = mysqli_real_escape_string($resdbcon, $stremail);  $strsubject = mysqli_real_escape_string($resdbcon, $strsubject);  $strmessage = mysqli_real_escape_string($resdbcon, $strmessage);   $strusername = stripslashes($strusername);  $stremail = stripslashes($stremail);  $strsubject = stripslashes($strsubject);  $strmessage = stripslashes($strmessage);   if (!filter_var($stremail, filter_validate_email)) {     senderror('invalid email address! please recheck email');  } elseif (!ctype_alnum($strusername) && strlen($strusername) > 10 && strlen($strusername) <= 3) {     senderror('invalid username! please make sure username alphanumeric , not long or short');  } elseif (!ctype_alnum($strsubject) && strlen($strsubject) < 5 && strlen($strsubject) > 10) {     senderror('invalid title! please enter valid subject, make sure alphanumeric , more 5 , lesser 10 characters long');  } elseif (!ctype_alnum($strmessage) && strlen($strmessage) < 5 && strlen($strmessage) > 500) {     senderror('invalid message! please enter valid message, make sure alphanumeric , more 5 , lesser 500 characters long');  }   $strheaders = "from: $stremail" . "\r\n" . "cc: $strcontactemail";      $strmessage = wordwrap($strmessage, 70);   $blnsent = mail($strcontactemail, $strsubject, $strmessage, $strheaders);     if ($blnsent) {     echo "<center><h2>thank contacting us, receive email within next 48 hours</h2></center>";  } else {     senderror('failed send email');  }  } else {  ?>  <center> <form class="form" name="form" method="post" action="<?php echo $_server['php_self']; ?>">    <input type="text" name="username" maxlength="10" placeholder="enter username">    <input type="text" name="email" maxlength="25" placeholder="enter valid email">    <input type="text" name="subject" maxlength="10" placeholder="enter subject">    <textarea  name="comments" maxlength="500" cols="25" rows="6" placeholder="enter message"></textarea>    <input type="submit" id="login-button" name="submit" value="submit"> </form> </center>  <?php   }   ?> 

try below

log google email account , go link: https://www.google.com/settings/security/lesssecureapps , set "access less secure apps" on.


Comments