1

I uploaded this php file on server and i want that when a user fills the html form present in this php file the user response should send to the email address that i mentioned in this php file .... but its not sending the response to the email address ... please help ... thank you

<?php 

if ($_POST["email"]<>'') { 

$ToEmail = 'abc@gmail.com'; 

$EmailSubject = 'Site contact form'; 

$mailheader = "From: ".$_POST["email"]."\r\n"; 

$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 

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

$MESSAGE_BODY = "Name: ".$_POST["name"].""; 

$MESSAGE_BODY .= "Email: ".$_POST["email"].""; 

$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; 

mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die 

("Failure"); 

?> 

  Your message was sent

  <?php 

  } else { 

?> 

<form action="test.php" method="post">

<table width="400" border="0" cellspacing="2" cellpadding="0">

<tr>

<td width="29%" class="bodytext">Your name:</td>

<td width="71%"><input name="name" type="text" id="name" size="32"></td>

</tr>

<tr>

<td class="bodytext">Email address:</td>

<td><input name="email" type="text" id="email" size="32"></td>

</tr>

<tr>

<td class="bodytext">Comment:</td>

  <td><textarea name="comment" cols="45" rows="6" id="comment"      
    class="bodytext">

     </textarea></td>

      </tr>

      <tr>

  <td class="bodytext"> </td>

 <td align="left" valign="top"><input type="submit" name="Submit"     

   value="Send">

  </td>

 </tr>

 </table>

  </form> 

  <?php 

  }; 

  ?>
abc
  • 13
  • 1
  • 5
  • So what exactly happens? Does it die ? Or does it display the "sent" message, but the mail doesn't come? – Oleg Dubas Jan 19 '15 at 05:28
  • when i click on submit button it displays message " your message was sent" but when i check the my email account there is no such email – abc Jan 19 '15 at 05:31
  • Is it a shared hosting? Or is it your server? Is it linux or windows? It is not guaranteed that `mail()` will send the email. it has to be configured properly to do it – Oleg Dubas Jan 19 '15 at 05:33
  • I am using OOOwebhost and i m using it in windows – abc Jan 19 '15 at 05:37
  • You should probably ask them then. windows systems have to have specific mail servers installed and configured so php could send mail with them. also consider using third party mail servers connecting to them via SMTP using PHPMailer class for example – Oleg Dubas Jan 19 '15 at 05:39
  • Check you junk/spam boxes 99% your email is there..., I would also try to send plain text email – talsibony Jan 19 '15 at 05:48
  • You obviously change this abc@gmail.com to your email right? – talsibony Jan 19 '15 at 05:51
  • @talsibony yes and there in no mail in spam/ junk – abc Jan 19 '15 at 06:55
  • Is this the first time you sending email from the server? check your php.ini file for the mail configuration – talsibony Jan 19 '15 at 08:29

2 Answers2

0

You're sending the email to the varible you defined earlier, $ToEmail. Change the value of that varible to the value you have from your form.

Try:

if ($_POST["email"]<>'') { 

$ToEmail = $_POST['email']; 

$EmailSubject = 'Site contact form'; 

$mailheader = "From: abc@gmail.com\r\n"; 

$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 

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

$MESSAGE_BODY = "Name: ".$_POST["name"].""; 

$MESSAGE_BODY .= "Email: ".$_POST["email"].""; 

$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"]).""; 
ilarsona
  • 436
  • 4
  • 13
0

Try using $mailheader = "From: admin@yourdomain"; for example email from asd.com must have $mailheader = "From: noreply@asd.com"; somilarly email from stackoverflow.com must have $mailheader = "From: admin@stackoverflow.com"; for authentic email sending. In some cases invalid email header causes failure to send email.

Homnath Bagale
  • 464
  • 1
  • 6
  • 32