0

I previously created a PHP mailer before, but for some reason, I cannot get this one to work.

I started using mysqli, but I don't think that really matters in this case.

So, I have a modal which contains a FORM called #addNewUserForm. Inside this FORM, I have various INPUTs that take in the following values:

 <form role="form" action="api/addUser.php" method="get" id="addNewUserForm" name="addNewUserForm">
 <input type="text" class="form-control username" id="username" name="username" />
 <input type="text" class="form-control fullname" id="fullname" name="fullname" />
 <input type="text" class="form-control" id="email" name="email" />

There are a few more INPUTs, but these three is what is necessary for sending the email.

So, once the user clicks this FORM BUTTON:

 <button type="submit" class="btn" id="addNewUserSubmit" name="addNewUserSubmit">Submit</button>
 </form>

I send the values over to a PHP file called addUser.php.

In addUser.php, begins like this:

 <?php
 if(isset($_GET['addNewUserSubmit']))
 {
   $username = mysqli_real_escape_string($_GET['username']);
   $full = mysqli_real_escape_string($_GET['fullname']);
   $email = mysqli_real_escape_string($_GET['email']);

   // I have some database processing here

   // now the mail feature

   $to = $_GET['email'];  // I also tried just using the $email variable
   $subject = 'Business Registration'; 
   $headers = "From: do not reply @ Business" . "\r\n";
   $headers .= "MIME-Version: 1.0\r\n";
   $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
   $message = "You have received a message from Business Applcation:<br /><br />";
   $message .= "Greetings <strong>" . $_GET['fullname'] . "</strong>,<br /><br />";  // also tried $full variable
   $message .= '<html><body>';
   $message .= '<table rules="all">';
   $message .= '<tr style="border: 1px solid black;"><th>User Name</th><th>Password</th></tr>';
   $message .= '<tr style="border: 1px solid black;"><td>';
   $message .= $_GET['username']; // also tried $username variable
   $message .= '</td><td>';
   $message .= 'password';  // something generic for now
   $message .= '</td></tr>';
   $message .= '</table>';
   $message .= '<body></html>';

   mail($to, $subject, $message, $headers);

 }
 ?>

So right now, when the user clicks the submit button (called #addNewUserSubmit), this page, addUser.php, receives all the values via GET, assigns them to variables, and then should run the MAIL feature, but does nothing. No email is sent (from what I can tell) and none is received.

Does anyone see anything wrong with this code?

halfer
  • 19,824
  • 17
  • 99
  • 186
John Beasley
  • 2,577
  • 9
  • 43
  • 89
  • Might be a good idea to output some debugging to see where the script ends. Maybe something after the mail function to prove that your code got that far. – Robbert Feb 03 '15 at 21:12
  • @Robbert, I can echo out $message and see how the email should look, as well as echo out all of the variables. It's just not being sent. – John Beasley Feb 03 '15 at 21:13
  • why are you using sql escapes on text going into an email context? And did you check the return value of `mail()`? You're simply assuming nothing could ever possibly go wrong... – Marc B Feb 03 '15 at 21:17
  • @Marc B - I used the escapes for the database processing (not shown), but if you'll notice, I didn't use them in the actual MAIL feature. If that is still wrong, please let me know. As far as checking the return value of mail(), please advise how I would do that? – John Beasley Feb 03 '15 at 21:21
  • `$status = mail(...); if (!$mail) { die("Mail failed"); }`. – Marc B Feb 03 '15 at 21:23
  • @Mar B, I added the code, and I get the DIE message. Any thoughts? – John Beasley Feb 03 '15 at 21:25
  • first thing i would do is check the mailserver log –  Feb 03 '15 at 21:25
  • then your php isn't configured to send email properly, and you'll have to investigate why. e.g. no local smtp server installed. – Marc B Feb 03 '15 at 21:25
  • @Marc B, thank you for your help. I will investigate further, and once I figure it out, I will answer this question. – John Beasley Feb 03 '15 at 21:27

0 Answers0