1

I'm not understanding why Im not receiving email from the form after filling out the simple form. After clicking the submit button it redirected to the thank you page with no problem, but no email.

HTML

<form class="action" name="form1" method="POST" action="_sendmail2.php" onSubmit="return CheckAll(this);">
    <label class="nick-2">Full Name:</label><br>
    <input type="text" class="name" name="full_name">
    <label class="nick">Email Address:</label><br>
    <input type="text" class="email" name="email"><br>
    <div class="radio-toolbar">  
        <input type="radio" id="radio1" name="agent_type" value="Buyer" checked>
        <label for="radio1">Buyer</label>
        <input type="radio" id="radio2" name="agent_type" value="Seller">
        <label for="radio2">Seller</label>
        <input type="radio" id="radio3" name="agent_type" value="Investor">
        <label for="radio3">Investor</label>
    </div><br>
    <input type="submit" class="btn" value="SUBMIT" name="Submit">
</form> 

PHP (

<?php 
$to = "cluneborg@hotmail.com"; 
$subject = "New Agent Inquries"; 
$full_name = $_POST['full_name']; 
$email = $_POST['email']; 
$agent_type = $_POST['agent_type'];

if($_SERVER['REQUEST_METHOD']=="POST") {    

$full_name=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['full_name']));  
$email=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['email']));  
$agent_type=str_replace ( array("\n"), array("   <br>"),trim($_REQUEST['agent_type']));   

$contentmsg=stripslashes("<br><b><font style=color:#CC3300>$subject</font></b><br>
<table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC>

 <tr>
  <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Full Name: </b> </td>
  <td width=565 align=left valign=top bgcolor=#FFFFFF> $full_name</td>
</tr>

<tr>
  <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Email Address: </b> </td>
  <td width=565 align=left valign=top bgcolor=#FFFFFF> $email</td>
</tr>

<tr>
  <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Type of Agent:</b> </td>
  <td width=565 align=left valign=top bgcolor=#FFFFFF> $agent_type</td>
</tr>

</table>
");

$headers  = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= 'To: Eric <eluneborg@gmail.com>' . "\r\n";
$headers .= 'From: Texas Real Estate Agent Website' . "\r\n";

if(mail($to,$subject,$contentmsg,$headers)){
header("Location: http://www.magnixsolutions.com/clients/tas/thanks.html"); 
} 
else
{ 
echo "Mail was not sent!"; 
} 
}
?>

Sometimes it sends email to my hotmail and most of time it get this (checked on cpanel)

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

cluneborg@hotmail.com
Domain magnixsolutions.com has exceeded the max defers and failures per hour (5/5      (55%)) allowed. Message discarded.
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    remove `@` sign and try – user123_456 Feb 14 '14 at 18:12
  • 1
    In PHP if you use `mail()` to send emails it is more than likely that your sending address will be identified with the address of the server which originally sent it (an MTA on your hosting provider). These kind of emails are often treated as spam because there is no way to prove that the email was not sent into MTA queue by some other user. That's why it wise to use SMTP instead which also provides mechanisms like DKIM signatures, authentication etc. to ensure the emails don't end up in spam. –  Feb 14 '14 at 18:29

3 Answers3

1

(Tested) - There were a few issues with your code.

  1. The most important thing, is the @ symbol in @mail - This will not execute, it needs to be removed.

Now, this line: (in PHP)

$_REQUEST['type_agent']

should be:

$_REQUEST['agent_type']

as per: (in HTML form)

<input type="radio" id="radio3" name="agent_type" value="Investor">

Then your headers were incorrect, where I added a few \r\n

One of your headers (in PHP)

$headers .= "From: ".$from."";

has been changed to:

$headers .= "From: $full_name <$email>\r\n";

Sidenote: It could be replaced with

$headers .= "From: $fromemail <$email>\r\n";

if you want the name to appear as "New Agent" in mail, instead of the person's name sending the Email.


Using this $fromemail="New Agent"; in conjunction with $from=$fromemail; and $headers .= "From: ".$from."";

would have resulted in mail going to SPAM, being it's not an actual Email address.

Plus, upon testing your original code, it did not come in as proper HTML, but the codes themselves showed up in the Email; that has been corrected.


If you want the Email and the name, you need to use two different variables.

I.e.:

$headers .= 'From: YourName <YourName@domain.com>' . "\r\n";

and in your case:

$headers .= "From: $full_name <$email>\r\n";

Rewrite: (PHP)

<?php ob_start();
// commented out - is not needed for the time being
// $fromemail="New Agent"; // change here if you want

$toemail="email@example.com";   // change here if you want

$sub="Agent Inquiries";          // change here if you want
$success_page_name="thanks.html";

////// do not change in following
if($_SERVER['REQUEST_METHOD']=="POST")
{
    $full_name=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['full_name']));  
    $email=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['email']));  
    $type_agent=str_replace ( array("\n"), array("<br>"),trim($_REQUEST['agent_type']));  

    $contentmsg=stripslashes("<br><b><font style=color:#CC3300>$sub</font></b><br>
    <table width=708 border=0 cellpadding=2 cellspacing=1 bgcolor=#CCCCCC>

    <tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Full Name: </b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>$full_name</td>
    </tr>

    <tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Email Address: </b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>$email</td>
    </tr>

    <tr>
      <td width=165 align=right valign=top bgcolor=#FFFFFF><B>Type of Agent:</b> </td>
      <td width=565 align=left valign=top bgcolor=#FFFFFF>$type_agent</td>
    </tr>

    </table>
    ");

    $headers  = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
    $headers .= "From: $full_name <$email>\r\n";

    @mail($toemail,$sub,$contentmsg,$headers);

    header("Location:$success_page_name");
}
?>

Footnotes:

  1. Including the @ symbol in @mail suppresses errors and does not execute the function, so you will want to remove it..

  2. In my testing, I removed onSubmit="return CheckAll(this); since your full code didn't include that function. Should it fail, then you may need to remove it also.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
0

You need to add EOL character \n in headers to separate. Don't know whether this is the solution, but it is at least one problem that needs attention.

$headers  = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";

$from=$fromemail;

$headers .= "From: ".$from."\n";

In addition to the error suppression answers/comments, you can also make sure that mail() returns true indicating your server has accepted it and will attempt delivery.

$success = mail($toemail,$sub,$contentmsg,$headers);
var_dump( $success ); // should be true
Patrick Moore
  • 13,251
  • 5
  • 38
  • 63
0

Remove the @ sign from the @mail command and it might give you a helpful error. The @ sign there is suppressing errors: http://www.php.net/manual/en/language.operators.errorcontrol.php

TrippyD
  • 735
  • 5
  • 9