NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP Code email Autoreply Help please

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 03-21-2011, 05:16 AM THREAD STARTER               #1 (permalink)
First Time Poster!
Join Date: Mar 2011
Posts: 1
mohamedselim is an unknown quantity at this point
 



PHP Code email Autoreply Help please


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 = 'myreiki11@gmail.com'; // 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.";
????: NamePros.com http://www.namepros.com/programming/707695-php-code-email-autoreply-help-please.html
$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>
&nbsp;</p>
<p align="left">&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<p align="left">&nbsp;</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>
????: NamePros.com http://www.namepros.com/showthread.php?t=707695
</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>
mohamedselim is offline   Reply With Quote
Old 03-21-2011, 06:30 AM   #2 (permalink)
NamePros Member
Join Date: Mar 2011
Posts: 47
jacobatwood is an unknown quantity at this point
 



You have to use the mail function in your php script that parses the form. Please check the php manual for how to use it at :

www.php.net/manual/en/function.mail.php for the reference.
__________________
█ A home to Virtual Machines!
Onshore/Offshore Managed VPS
Managed HardCore Ultimate VPS Offshore/Onshore
jacobatwood is offline   Reply With Quote
Old 03-21-2011, 06:58 AM   #3 (permalink)
NamePros Regular
 
baxter's Avatar
Join Date: Apr 2006
Posts: 360
baxter is just really nicebaxter is just really nicebaxter is just really nicebaxter is just really nice
 


Ethan Allen Fund Save The Children
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,
????: NamePros.com http://www.namepros.com/showthread.php?t=707695

Jay
__________________
Canadian Domain Registrar Ready.ca
baxter is offline   Reply With Quote
Old 03-21-2011, 08:30 PM   #4 (permalink)
If only you knew...
 
maximum's Avatar
Join Date: Oct 2005
Location: Inside your head...
Posts: 990
maximum has a reputation beyond reputemaximum has a reputation beyond reputemaximum has a reputation beyond reputemaximum has a reputation beyond reputemaximum has a reputation beyond reputemaximum has a reputation beyond reputemaximum has a reputation beyond reputemaximum has a reputation beyond reputemaximum has a reputation beyond reputemaximum has a reputation beyond reputemaximum has a reputation beyond repute
 


Child Abuse Special Olympics Save a Life Baby Health Autism
baxter
__________________
--- The greatest truths ever told, and the greatest lies ever told, all consist of exactly the same three words:
"I LOVE YOU"
--- The best say little, only say what is important.....then they shut up and sit down.
maximum is offline   Reply With Quote
Old 03-21-2011, 08:46 PM   #5 (permalink)
Account Suspended
Join Date: Dec 2008
Location: Boston, Ma
Posts: 650
CrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to all
 



Marrow Donor Program Animal Rescue Autism Autism
Ouch, don't touch the mail() function. Bad juju. Mail() = no no no no no

Checkout php mailer for php4 and use this function:

PHP Code:

????: NamePros.com http://www.namepros.com/showthread.php?t=707695
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;
????: NamePros.com http://www.namepros.com/showthread.php?t=707695
           } else {
               return 
true;
           }
    }

To use just do this:

PHP Code:


$smtphost     
'mail.YOURDOMAIN.com';
$smtpfromname     'NAME SENDING AS';
$smtpfromaddress 'EMAIL@YOURDOMAIN.COM';
$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 by CrackFeed.Com; 03-21-2011 at 08:49 PM.
CrackFeed.Com is offline   Reply With Quote
Old 03-26-2011, 03:19 PM   #6 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,074
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Originally Posted by DomainerHelper View Post
Checkout php mailer for php4 and use this function:
I seriously hope you are not still using PHP 4. PHP 4 is now defunct and does not get proper updates. If you are still using PHP 4 ten I seriously suggest upgrading or changing host if they do not offer it.
????: NamePros.com http://www.namepros.com/showthread.php?t=707695

The PHP 5 version of that package is located at http://sourceforge.net/projects/phpm...0for%20php5_6/
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline   Reply With Quote
Old 03-26-2011, 03:53 PM   #7 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by Peter View Post
I seriously hope you are not still using PHP 4. PHP 4 is now defunct and does not get proper updates. If you are still using PHP 4 ten I seriously suggest upgrading or changing host if they do not offer it.
????: NamePros.com http://www.namepros.com/showthread.php?t=707695

The PHP 5 version of that package is located at http://sourceforge.net/projects/phpm...0for%20php5_6/
Indeed. But SwiftMailer is even better.
Eric is offline   Reply With Quote
Old 03-26-2011, 04:29 PM   #8 (permalink)
Account Suspended
Join Date: Dec 2008
Location: Boston, Ma
Posts: 650
CrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to allCrackFeed.Com is a name known to all
 



Marrow Donor Program Animal Rescue Autism Autism
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.
CrackFeed.Com is offline   Reply With Quote
Old 03-28-2011, 08:30 PM   #9 (permalink)
NamePros Member
Join Date: Mar 2011
Posts: 44
rolandkeys is an unknown quantity at this point
 



How to configure swiftmail with and smtp authentication and ssl connection port?...

Thanks in advance
__________________
Unpredictable & Powerful!
richard fifer Wife richard fifer Dogs richard fifer Horses
rolandkeys is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
MATRIMONIAL script in php, Bug error FREE source code samser_m Scripts For Sale 0 09-10-2009 01:16 PM
Mega Script Pak apower Scripts For Sale 7 03-14-2008 09:25 PM
19 Company 'Top List' Databases For Sale odditysoftware Content For Sale 0 06-09-2006 11:50 AM
Needed: 'Email a friend' php code with . . . cjcjcj Programming 7 06-29-2005 12:06 AM

 
All times are GMT -7. The time now is 02:45 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger