Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

correction in code

the mail() function

Moderators: macek, egami, gesf

correction in code

Postby srinivas » Thu Jan 12, 2012 5:24 am

can someone help me in correcting the code below. i am not receiving mails to my mail id contact@acmetechinc.com.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<a>
<?php
if(isset($_POST['email'])) {
$email_to = "contact@acmetechinc.com";
function died($error) {
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['subject']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // required
$subject = $_POST['subject']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .-]+$/";
if(!preg_match($string_exp,$subject)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
$string_exp = '/^[0-9]+$/';
if(!preg_match($string_exp,$telephone)) {
$error_message .= 'The phone number you entered not appear valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .="subject: ".clean_string($subject)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
$headers = 'MIME-Version : 1.0'."\r\n";
$headers = 'content-type:text/html; charset=utf-8'. "\r\n";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
</a>
</body>
</html>

the script is working because i am getting the html page with the message " Thank you for contacting us. we will be in touch with you very soon."
srinivas
New php-forum User
New php-forum User
 
Posts: 5
Joined: Fri May 13, 2011 4:06 am

Re: correction in code

Postby jorgepinho » Thu Jan 12, 2012 6:17 am

Hi,

Is there any PHP error ?
jorgepinho
New php-forum User
New php-forum User
 
Posts: 101
Joined: Tue Jul 05, 2011 5:41 am
Location: Portugal

Re: correction in code

Postby egami » Thu Jan 12, 2012 7:19 am

died('We are sorry, but there appears to be a problem with the form you submitted.');
}


should be:
die('We are sorry, but there appears to be a problem with the form you submitted.');
}

** HINT: lose the extra 'd' in die(d)
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: correction in code

Postby srinivas » Thu Jan 12, 2012 9:14 pm

the code i think is working fine. it is displaying the message as "thank you for contacting us. we will get back to you very soon."
srinivas
New php-forum User
New php-forum User
 
Posts: 5
Joined: Fri May 13, 2011 4:06 am

Re: correction in code

Postby egami » Fri Jan 13, 2012 6:35 am

so, let's see.
according to PHP.net/mail..

the PROPER SYNTAX is:

mail(to,subject,message,header)

not..

mail(to,message,header)

mmmmkay?
mmmkay!
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron