0

I'm trying to have a contact form on my page. Nothing crazy, just a simple form. I've tried multiple contact forms from the web, and they all look fine, they all work fine when filling it out on my site and even when you hit submit it brings you to the PHP page fine and everything, but I never get the message in my email. I've checked my spam and everything and I'm just not getting the message.

Here's the form html:

<form method="post" action="sendit.php">
    <label for="Name">Name:</label>
    <input type="text" name="Name" id="Name" />

    <label for="Phone">Phone:</label>
    <input type="text" name="Phone:" id="Phone" />

    <label for="Email">Email:</label>
    <input type="text" name="Email" id="Email" />

    <label for="Message">Message:</label>
    <textarea name="Message" rows="20" cols="20" id="Message"></textarea>

    <input type="submit" name="submit" value="Submit" class="submit-button" />
</form>

Here's the PHP:

<?php
$EmailFrom = "mjd8079@yahoo.com";
$EmailTo = "mjd8079@yahoo.com";
$Subject = "Contact";
$Name = Trim(stripslashes($_POST['Name'])); 
$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email'])); 
$Message = Trim(stripslashes($_POST['Message'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=sendit.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
default locale
  • 13,035
  • 13
  • 56
  • 62
Megan
  • 11

2 Answers2

0

This is the piece of the code which will help you to send the email as well as, it would ensure approx 80% that the mail will deliver in Inbox and not in Spam

require_once "Mail.php";
require_once('Mail/mime.php');

$to = "mjd8079@yahoo.com";
$subject = "Contact";
$header = "from: Some Name <mjd8079@yahoo.com> \r"."<br >";
$header .= "Content-Type: text/html; charset=ISO-8859-1 \r"."<br >";
$header .= "Return-Path: <mjd8079@yahoo.com> \r"."<br >";
$header .= "X-Priority: 1 (Highest) \r"."<br >";
$header .= "X-MSMail-Priority: High \r"."<br >";
$header .= "Importance: High \r"."<br >"; 
$header .= "MIME-Version: 1.0 \r"."<br >";

$htmlbody = "<html>
    <table width='430' border='1' cellpadding='5' cellspacing='5' class='bg1' style='border-collapse:collapse;'>
      <tr>
        <td width='185' bgcolor='#003366'><font color='#ffffff' face='Verdana'>Your Name:</font></td>
        <td width='210' valign='middle' bgcolor='#FFFFCC'><font color='#000000' face='Verdana' style='font-weight:bold'>$name</font></td>
      </tr>
      <tr>
        <td bgcolor='#003366'><font color='#ffffff' face='Verdana'>E mail</font></td>
        <td bgcolor='#FFFFCC'><font color='#000000' face='Verdana' style='font-weight:bold'>$Email</font></td>
      </tr>
      <tr>
        <td bgcolor='#003366'><font color='#ffffff' face='Verdana'>Telephone Number</font></td>
        <td bgcolor='#FFFFCC'><font color='#000000' face='Verdana' style='font-weight:bold'>$Tel</font></td>
      </tr>
      <tr>
        <td bgcolor='#003366'><font color='#ffffff' face='Verdana'>Message</font></td>
        <td bgcolor='#FFFFCC'><font color='#000000' face='Verdana' style='font-weight:bold'>$Message</font></td>
      </tr>
    </table>
</html>";

$from = "Some Name <mjd8079@yahoo.com>";
$host = "smtp.yahoo.com";
$port = "587";
$username1 = "mjd8079@yahoo.com";
$password1 = "yourpassword";
$crlf = chr(10);
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setHTMLBody($htmlbody);
$body = $mime->getMessageBody();
$headers = array ('From' => $from,
                    'To' => $to,
                    'Subject' => $subject);
$headers = $mime->headers($headers);

$smtp = Mail::factory('smtp', 
        array ('host' => $host, 
                'port' => $port, 
                'auth' => true, 
                'username' => $username1, 
                'password' => $password1)
            );
$mail = $smtp->send($to, $headers, $body );
Mohit S
  • 13,723
  • 6
  • 34
  • 69
0

There may be no issues with your code you may need to confirm that the server running PHP has an smtp server setup on it and that PHP knows about it.

You will have to check in you php.ini file to see in a server has been setup, the setting can be seen hear http://php.net/manual/en/mail.configuration.php.

if you also have access to the commandline on the server you can test that the server has access to send emails by doing the command

/usr/sbin/sendmail -t -i mjd8079@yahoo.com
This is a test
ctrl-d

if you don't get a message then it is most like the server not the code

tho in my experience Yahoo can be a bit grumpy on sending to may email, and can start blocking email if there is to many in a short period of time, so try another email address

jazzjazzy
  • 412
  • 3
  • 20