Jump to content

Standard Mail Function is Not Sending Email


JTCoder

Recommended Posts

Hello,

 

I am fairly new to PHP, and have just written some code to send from a simple form. However it is failing to send the information typed into the form.

I have made sure to give each form field an ID, and have specified the matching ID as an index in the POST array.

 

Once the form is submitted, the captcha utility verifies the text, then an if/else statement redirects to either an 'oops' page, or a 'submission successful' page. The PHP code on the 'submission successful' page then sends the info from the POST array to the specified email address using the mail() function. The code on the 'submission successful' page is as follows:

 

<?php

if(isset($_POST['submit'])) {

  $to = '[email protected]' ;    //put your email address on which you want to receive the information

  $subject = 'Inquiry';  //set the subject of email.

  $headers = 'MIME-Version: 1.0' . "\r\n";

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

  $message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>

              <tr><td>E-Mail</td><td>".$_POST['email']."</td></tr>

              <tr><td>Contact No</td><td>".$_POST['contact']."</td></tr>

              <tr><td>Message</td><td>".$_POST['message']."</td>

              </tr></table>" ;

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

}

?>

 

Thank you for your assistance.

 

Jesse

Thank you for your responses; much appreciated.

 

I have made the following corrections based on your responses and the PHP Manual, and am not receiving email. I checked the form, and the name attributes for each input tag are set.

 

<?php

if(isset($_POST['submit'])) {

  $to = '[email protected]' ;    //put your email address on which you want to receive the information

  $subject = 'Thuris Media Enquiry';  //set the subject of email.

  $headers = 'MIME-Version: 1.0' . "\r\n";

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

  $headers .= 'From: Test <[email protected]>' . "\r\n";

  $message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>

              <tr><td>E-Mail</td><td>".$_POST['email']."</td></tr>

              <tr><td>Contact No</td><td>".$_POST['contact']."</td></tr>

              <tr><td>Message</td><td>".$_POST['message']."</td>

              </tr></table>" ;

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

}

?>

 

Thanks for your help, guys.

Jesse

Also you need to check with the host. Some hosts require that you have 'sendmail_from' set to a valid address in your domain either in the php.ini or with ini_set() in the script. Also these same hosts require the 5th parameter to mail() to be used as -f"[email protected]"  which would contain the same email address as the sendmail_from.

 

The only host I know requires this, is fasthosts in the UK, but could apply to others.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.