Jump to content

PHP Mailler Script (Need Help)


btsolutions

Recommended Posts

I am in need of some help on a php mailer script, here is what I have. Everything is working in regards to detecting errors and echoing a response on submission. However, I am not receiving an email once it has been submitted.

 

I am rather to new to the realm of php mailers and could use some help.

 

 

<?php

 

$name = trim($_POST['name']);

$email = $_POST['email'];

$comments = $_POST['comments'];

 

if (strlen($name) < 2) {

$error['name'] = "Please enter your name";

}

 

if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {

$error['email'] = "Please enter a valid email address";

}

 

if (strlen($comments) < 3) {

$error['comments'] = "Please leave a comment.";

}

 

if (!$error) {

 

                $mail->$to = "[email protected]"; // Your email address to send to

$mail->From = $email;

$mail->FromName = $name;

$mail->Subject = "Contact Form Submission";

$mail->Body = $comments;

 

echo "<li class='success'> Thanks, " . $name . ". We've received your email. We'll be in touch as soon as we possibly can! </li>";

 

} # end if no error

else {

 

$response = (isset($error['name'])) ? "<li>" . $error['name'] . "</li> \n" : null;

$response .= (isset($error['email'])) ? "<li>" . $error['email'] . "</li> \n" : null;

$response .= (isset($error['comments'])) ? "<li>" . $error['comments'] . "</li>" : null;

 

echo $response;

} # end if there was an error sending

 

?>

Link to comment
https://forums.phpfreaks.com/topic/165655-php-mailler-script-need-help/
Share on other sites

is this all of your mailer code?? You dont seem to be telling php to send the email??

 

You will need to uses php's mail function, (see here for info)

 

   if (!$error) {
      
      $to = "[email protected]"; // Your email address to send to   
      $From = $email;
      $FromName = $name;
      $Subject = "Contact Form Submission";
      $Body = $comments;
	$headers = 'From: '.$from.'' . "\r\n" .
    'Reply-To: '.$from.'' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

     if($t = mail($to,$subject,$body,$headers)){
      echo "<li class='success'> Thanks, " . $name . ". We've received your email. We'll be in touch as soon as we possibly can! </li>";
      }else{
echo "<li>Unable to send E-mail</li><br />";
}
   } # end if no error
   else {

      $response = (isset($error['name'])) ? "<li>" . $error['name'] . "</li> \n" : null;
      $response .= (isset($error['email'])) ? "<li>" . $error['email'] . "</li> \n" : null;
      $response .= (isset($error['comments'])) ? "<li>" . $error['comments'] . "</li>" : null;
      
      echo $response;
   } # end if there was an error sending

The example above should now send any emails supplied to it,

 

 

Hope it helps

 

Stuie

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.