Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

PHP Code email Autoreply Help please

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch
Impact
0
i have a page in my website with PHP , that do a customer comment and it send me an emails for those comments , and then send an automatic email to the customer , but my only problem is that i want the customer to receive the email as it is from the email i got my emails on , but when the customer received the email it received as my username in my host site @ hostsite.com

i want to solve this please thanks.

here is the code :


<?php
require_once('recaptchalib.php');

$errFlag=0;
$showForm=1;

//KEEP YOUR PRIVATE KEY HERE
$privatekey = ""; // << replace this key with yours


function isValidEmail($email){
return filter_var(filter_var($email, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
}

if (isset($_POST["submit"])){
$name=$_POST['name'];
$lname=$_POST['lname'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$message=$_POST['message'];

if(empty($_POST))
{
$errMsg[]="Please enter all the field.";
}
if(empty($name))
{
$errMsg[]="Please enter your First Name.";
}
if(empty($lname))
{
$errMsg[]="Please enter your Last Name.";
}
if(empty($phone))
{
$errMsg[]="Please enter phone number.";
}
elseif(!is_numeric($phone))
{
$errMsg[]="Please enter valid phone number.";
}
if(empty($email))
{
$errMsg[]="Please enter an email address.";
}
elseif(!isValidEmail($email))
{
$errMsg[]="Please enter an valid email address.";
}

if(empty($message))
{
$errMsg[]="Please enter message.";
}

/* captcha validation */
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
$errMsg[]="The CAPTCHA wasn't entered correctly. Please try it again.";
}

if(empty($errMsg))
{
// if there is no error then send a mail
$ToEmail = '[email protected]'; // CHANGE YOUR EMAIL WHERE YOU WANT TO RECEIVE THE CONTACT FORM SUBMITTED BY USERS...
$EmailSubject = 'Customer Comments ';
$mailheader = "From: ".$email."\r\n";
$mailheader .= "Reply-To: ".$email."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$name." ".$lname."<br>";
$MESSAGE_BODY .= "Phone: ".$phone."<br>";
$MESSAGE_BODY .= "Email: ".$email."<br>";
$MESSAGE_BODY .= "Comment: ".nl2br($message)."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
if(mail)
{
$msg="Thank your for submitting the form, we will contact your shortly.";
$showForm=0;
mail($email, "Thank your for submitting.", $msg);
} else
{
$msg="Some errors occured, please try again in a while.";
}
} else
{
$errFlag=1;
}



}

?>
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns="urn:schemas-microsoft-comfficeffice" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<link rel="shortcut icon"
href="http://www.divineenergyhealing.co/favicon.ico">
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Customer Comments</title>
<meta name="description" content="Customer Comments">
<link rel="File-List" href="reiki website/Reiki/Customer Comments_files/filelist.xml">

<base target="_self">
<!--[if !mso]>
<style>
v\:* { behavior: url(#default#VML) }
o\:* { behavior: url(#default#VML) }
.shape { behavior: url(#default#VML) }
</style>
<![endif]--><!--[if gte mso 9]>
<xml><o:shapedefaults v:ext="edit" spidmax="1027"/>
</xml><![endif]-->

<style type="text/css">
/* error and success msg */
#errMsg { background-color:#febbbb; border:1px solid #d31a1c; color:#d31a1c; font-size:12px; padding:10px; margin-bottom:15px;}
#successMsg { background-color:#ffffff; border:1px solid #ffffff; color:#000000; font-size:16px; padding:10px; margin-bottom:15px; margin-top:25px;}

#contact_form { position: absolute; width: 888px; height: 365px; z-index: 1; left: 190px; top: 128px;}

#contact_form form label { display:block;}
contact_form p { margin-bottom:10px;}
.auto-style1 {
font-family: "Times New Roman", Times, serif;
font-weight: bold;
color: #FFFFFF;
}
</style>

</head>

<body link="#0000FF" vlink="#800000" alink="#FF0000">

<p>
 </p>
<p align="left"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>        </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>

<p align="left"> </p>

<div id="contact_form" style="left: 192px; top: 102px">
<?php
if($errFlag)
{
echo "<div id='errMsg'>";
foreach($errMsg as $val)
{
echo "- ";
echo $val;
echo "<br />";
}
echo "</div>";
}
?>
<?php if($showForm){ ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="contact_form" method="post">
<p>
<label for="name">First Name</label>
<input name="name" type="text" id="name" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" />
</p>
<p style="height: 45px">
<label for="lname">Last Name</label><input name="lname" type="text" id="lname" style="width: 148px; height: 22px" value="<?php if (isset($_POST['lname'])) echo $_POST['lname']; ?>" />
</p>
<p>
<label for="phone">Phone Number</label>
<input name="phone" type="text" id="phone" value="<?php if (isset($_POST['phone'])) echo $_POST['phone']; ?>" />
</p>
<p>
<label for="email">Email Address</label>
<input name="email" type="text" id="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" />
</p>
<p>
<label for="message">Customer Comments</label>
<textarea name="message" id="message" style="width: 247px; height: 84px" rows="999"><?php if (isset($_POST['message'])) echo $_POST['message']; ?></textarea>
</p>
<p>
<?php
//PUT YOUR PUBLIC KEY HERE
$publickey = ""; // << replace this key
echo recaptcha_get_html($publickey);
?>
</p>

<p><input name="submit" type="submit" value="Submit" /> <input name="reset" type="reset" value="Reset" /></p>
</form>
<?php } else { ?>
<div id="successMsg" class="auto-style1">Thanks for your comments and questions we appreciate that you took the time to send us..</div>
<?php }?>
</div>

</body>

</html>
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
Close
Change this line:

Code:
mail($email, "Thank your for submitting.", $msg);

to: ( Replacing <EMAIL> with the email you want it sent from )

Code:
$headers = 'From: <EMAIL>' . "\r\n" .
    'Reply-To: <EMAIL>';

mail($email, "Thank your for submitting.", $msg, $headers);

Cheers,

Jay
 
1
Close
baxter:tu:
 
0
Close
Ouch, don't touch the mail() function. Bad juju. Mail() = no no no no no :D

Checkout php mailer for php4 and use this function:

PHP:
if (!function_exists('sendEmail')) {
	function sendEmail($email,$subject,$message) {
		Global $smtphost,$smtpport,$smtpfromaddress,$smtpfrompassword,$smtpfromaddress,$smtpfromname;
	   	require('/path/to/phpmailer/class.phpmailer.php');
	   	$mail = new PHPMailer();
	   	$mail->IsSMTP();
	   	$mail->SMTPDebug = 0;
	   	$mail->SMTPAuth = TRUE;
	   	$mail->IsHTML(TRUE);
	   	$mail->Host    = $smtphost;
	   	$mail->Port    = $smtpport;
	   	$mail->Username  = $smtpfromaddress;
	   	$mail->Password  = $smtpfrompassword;
	   	$mail->From    = $smtpfromaddress;
	   	$mail->FromName  = $smtpfromname;
	   	$mail->Subject  = $subject;
	   	$mail->Body    = nl2br(htmlspecialchars(strip_tags($message)));
	   	$mail->AltBody  =  htmlspecialchars(strip_tags($message));
	   	$mail->AddAddress($email, $email);
	   	if(!$mail->Send()) {
	   		return false;
	   	} else {
	   		return true;
	   	}
	}
}

To use just do this:

PHP:
$smtphost 	= 'mail.YOURDOMAIN.com';
$smtpfromname 	= 'NAME SENDING AS';
$smtpfromaddress = '[email protected]';
$smtpfrompassword = 'YOURPASSWORD';
$smtpport = 26; // or port 25 usually
if (!sendEmail($email,$subject,$message) {
         // email did not send so now what? Maybe THEN try using mail() as a backup.
} else {
        // ok, the email sent via php mailer... groovy.
}


Now you are less likely to be put into a spam folder and most likely for your email to reach it's destination. mail() blows chunks.

Send the $message to the function in plain text with \n for line breaks and this will send a plain text and html format email in one. This is good practice.


Good luck!
 
Last edited:
0
Close
0
Close
0
Close
Of course not, I posted the php4 version because I do not know what the guy uses. You know, "Keep it simple". Relax peeps. I run PHP 5.3.6, I have dedicated. Anyhoo, stay away from the mail() construct, is my point.
 
0
Close
How to configure swiftmail with and smtp authentication and ssl connection port?...

Thanks in advance
 
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back