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@gmail.com' ;    //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

Link to comment
Share on other sites

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 = 'jessejuhlke@gmail.com' ;    //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 <test@test.com>' . "\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

Link to comment
Share on other sites

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"name@yourhost.com"  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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.