had alot fo problems making a functional contact form tonight. After messing for hours i finally found out that i can only use SMTP with my web hoster.
Can anyone please advice me how i can complete my form?
This is my current SMTP PHP Form
$mail = new PHPMailer();
//Your SMTP servers details
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "localhost"; // specify main and backup server or localhost
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "enquiries#c(hidden)y.co.uk"; // SMTP username
$mail->Password = "******"; // SMTP password
//It should be same as that of the SMTP user
$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = "Display Name";
$mail->AddAddress("enquiries#c(hidden)y.co.uk", "chapnolo"); //Email address where you wish to receive/collect those emails.
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $_POST['subject'];
$message = "Name of the requestor :".$_POST['fullname']." \r\n <br>Email Adrress :".$_POST['email']." \r\n <br> Query :".$_POST['query'];
$mail->Body = $message;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
header("Location: $redirect_url");
}
?>
I need my form to have the following functionality for me to retrieve the requires e-mail message body.
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
$web = $_POST['web'];
$formcontent="From: $name \n Contact: $number \n Website: $web \n Message: $message";
$recipient = "enquiries#c(hidden)y.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email ";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
Help will be greatly appreciated
Metexora - So you're not having any issues with the code, you just haven't told it to send you the name contact number, email and message body - just change:
$message = "Name of the requestor :".$_POST['fullname']." \r\n <br>Email Adrress :".$_POST['email']." \r\n <br> Query :".$_POST['query'];
to
$message = "Name of the requestor :".$name." \r\n <br>Email Adrress :".$email." \r\n <br> Phone number :".$number."\r\n <br> Message: ".$message."\r\n <br> Website: ".$web;
(Note: Be careful, you are re-declaring $message here, that isn't really recommended practise given they refer to different things, the user message and the email message, you should only use the change the contents of a variable if it still refers to the same thing)
Related
My code is as given below. I would like to know how to use smtp function in php with authentication in contact form. If I use hotmail id I am not able to recive the inquiry but it works fine for gmail id. It would be great if someone help in me editing my code noted below
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent=" Name: $name \n Email: $email \n Phone: $phone \n Message: $message";
$to = "abc#hotmail.com";
$subject = "Contact Form";
$mailheader = "From: $name \r\n";
mail($to, $subject, $formcontent, $mailheader) or die("Error!");
echo "<br><br><p style='color:#000'><b>Thank You $name</b></p><p style='color:#000'>We will be in touch as soon as possible.</p>";
echo "<p style='color:#000'>Go to <a href='index.html'><b>Home Page</b></a></p>";
?>
You can use PHPMailer Library to do this.
Example:
$mail = new PHPMailer();
$mail->SMTPSecure = 'tls';
$mail->Username = "abc#hotmail.com";
$mail->Password = "Your password";
$mail->AddAddress("mymail#hotmail.com");
$mail->FromName = "Your Name";
$mail->Subject = "Contact Form";
$mail->Body = "The Body";
$mail->Host = "smtp.live.com";
$mail->Port = 587;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->From = $mail->Username;
$mail->Send();
I get email but i am not getting the content from the form though I have removed enctype tag from form Below is output i get in body of email
Name:
Organisation:
Postal Address:
City:
Country:
Email:
Telephone:
Comments:
what is wrong thing done by me can anyone help.
<?php
require("/home/public_html/phpMailerTesting/PHPMailer_5.2.0/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "localhost"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "sendfromphpmailer#xxx.com"; // SMTP username
$mail->Password = "12345"; // SMTP password
enter code here
$name=$_POST['name'];
$email=$_POST['mail'];
$message=$_POST['comment1'];
$mail->From ="sendfromphpmailer#xxx.com" ;
$mail->FromName = $_POST["name"];
$mail->AddAddress("receivefromphpmailer#xxx.com");
// name is optional
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "You have received feedback from your website!";
$mail->Body = "Name:$name
Organisation: $organisation
Postal Address: $PostalAddress
City: $City
Country: $Country
Email: $email
Telephone: $telephone
Comments: $comments";
//$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
I like phpMailer but when I used a previous mailer it had an anti spam code.
You added a hidden field in the contact form and the mail.php script was coded that if the hidden field was filled in (i.e. only a spam robot would do that) the mail wouldnt send
How would I add that to this script?
This is my mail.php code as follows
<?php
// $email and $message are the data that is being
// posted to this page from our html contact form
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$name = $_REQUEST['name'] ;
$phone = $_REQUEST['phone'] ;
$address = $_REQUEST['address'] ;
$postcode = $_REQUEST['postcode'] ;
$service = $_REQUEST['service'] ;
$height = $_REQUEST['height'] ;
$how = $_REQUEST['how'] ;
$website = $_REQUEST['website'] ;
$mail_intro ="The following enquiry came from your web site:";
// When we unzipped PHPMailer, it unzipped to
// public_html/PHPMailer_5.2.0
require("class.phpmailer.php");
$mail = new PHPMailer();
// set mailer to use SMTP
$mail->IsSMTP();
// As this email.php script lives on the same server as our email server
// we are setting the HOST to localhost
$mail->Host = "localhost"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "franchise#website.co.uk"; // SMTP username
$mail->Password = "passowrd"; // SMTP password
$mail->From = "noreply#website.co.uk";
$mail->FromName = "B";
$mail->AddReplyTo($email,$name);
$mail->AddAddress("franchise#website.co.uk", "B");
$mail->AddBCC("joseph#website.co.uk", "Joseph");
$response="$mail_intro\n<br />Name: $name\n<br />Email: $email\n<br />Phone: $phone\n<br />Address: $address\n<br /> Comments:\n$message\n<br /> Website: $website\n";
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
$mail->Subject = "Enquiry";
// $message is the user's message they typed in
// on our contact us page. We set this variable at
// the top of this page with:
// $message = $_REQUEST['message'] ;
$mail->Body = $response;
$mail->AltBody = $message;
//Autoresponder
$mailto="$email";
$subject="Franchisee Enquiry";
$body.="Thanks for your enquiry, the message below has been sent. \n";
$body.="If due to an unknown technical error you do not receive a response within 4 hours please phone \n";
$body.="or email us directly at info#website.co.uk where we will be only too happy to help.\n";
$body.="$mail_intro\n";
$body.="Name: $name\n";
$body.="Email: $email\n";
$body.="Phone: $phone\n";
$body.="Postcode: $postcode\n";
$body.="Service Required: $service\n";
$body.="How found: $how\n";
$body.="Comments:\n$message\n";
mail($mailto,$subject,$body,"From: noreply#website.co.uk\n");
if(!$mail->Send())
{
header("Location: http://website.co.uk/error.php");
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
header("Location: http://website.co.uk/thankyou.php");
?>
In your HTML, add:
<input type="text" name="fooBarBaz" style="display: none">
And in your PHP:
if ( !empty($_REQUEST['fooBarBaz']) )
{
// hidden field was filled out, do something about it
}
else
{
$email = $_REQUEST['email'];
...
}
I'm using PHPMailer to successfully send an email upon a webform submission (so just using basic post data, no mysql databases or any lookups).
What I need to do is send two seperate emails, one version for the customer and the other for a customer service agent - so that when a user completes a webform, they will receive a 'marketing' version of the email, whilst the customer service agent will receive an email just containing the details submitted by the user.
See below what im using at the moment, but not sure how to best implement to send the secoind email? It presently fails and the script exits after sending only one email.
$body = ob_get_contents();
$to = 'removed';
$email = 'removed';
$fromaddress = "removed";
$fromname = "removed";
require("phpmailer.php");
$mail = new PHPMailer();
$mail->From = $fromaddress;
$mail->FromName = $fromname ;
$mail->AddAddress("email#example.com");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = "Subject";
$mail->Body = $body;
$mail->AltBody = "This is the text-only body";
if(!$mail->Send()) {
$recipient = 'email#example.com';
$subject = 'Contact form failed';
$content = $body;
mail($recipient, $subject, $content,
"From: mail#yourdomain.com\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
exit;
}
//Send the customer version
$mail=new PHPMailer();
$mail->SetFrom('email', 'FULLNAME');
$mail->AddAddress($mail_vars[2], 'sss');
$mail->Subject = "Customers email";
$mail->MsgHTML("email body here");
//$mail->Send();
In the customer version you are not setting the email's properties the same way you are in the first. For example you use $mail->From = $fromaddress; in the first and $mail->SetFrom('email', 'FULLNAME'); in the second.
Because you instantiated a new $mail=new PHPMailer(); you need to set the properties again.
Instead of just bailing out with a useless "something didn't work" message, why not have PHPMailer TELL you what the problem is?
if (!$mail->send()) {
$error = $mail->ErrorInfo;
echo "Mail failed with error: $error";
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
PHP's mail() function has stopped sending my emails. I talked with my service provider and they said I have to use SMTP however i am not professional php developer. They tried to give a little help and they provided me with a script which sends email to me when a user submit a form, but my old form used to send email to me of the clent data as well as a confirmation email email to the client.
The new script i have manged some how to send a confirmation email for the client, but I don't know how send email with this script, can you tell me what I should add to make it work?
if(isset($_POST['submit']))
{
$title = $_POST['title'];
$name = $_POST['name'];
$surname = $_POST['surname'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$state = $_POST['us'];
$details = $_POST['details'];
$reasons = $_POST['re'];
$content = $_POST['message'];
require("class.phpmailer.php");
$mail = new PHPMailer();
//Your SMTP servers details
// set mailer to use SMTP
$mail->IsSMTP();
// specify main and backup server or localhost / your mail server yourmailserver.com
$mail->Host = "xxxxxx.example.com";
// turn on SMTP authentication
$mail->SMTPAuth = true;
// SMTP username
$mail->Username = "me#xxxxx.com";
$mail->Password = "**********"; // SMTP password
//It should be same as that of the SMTP user
$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
//$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = "Admin";
//Email address where you wish to receive/collect those emails.
$mail->AddAddress($visitor_email, "");
$mail->WordWrap = 50;// set word wrap to 50 characters
$mail->IsHTML(true);// set email format to HTML
$mail->Subject = 'You have mail from: www.example.com';
// ** Build the Message
$message = "<h4><b>We received your query</b></h4><br/><br/>";
$message .="Thankyou for contacting example.net.<br/>";
$message .="<br>";
$message .="Regards,<br/>";
$message .="admin";
$mail->Body = $message;
//header("Location: thank-you.html");
if(!$mail->Send())
{
header('Location: thank-you.html');
// echo "Message could not be sent. <p>";
// echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
header('Location: thank-you.html');
}
else{
header('Location: contact-us.html');
}
?>
// ******** Second update
<?
ob_start();
if(isset($_POST['submit']))
{
$title = $_POST['title'];
$name = $_POST['name'];
$surname = $_POST['surname'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$state = $_POST['us'];
$details = $_POST['details'];
$reasons = $_POST['re'];
$content = $_POST['message'];
require("class.phpmailer.php");
$mail = new PHPMailer();
//Your SMTP servers details
// set mailer to use SMTP
$mail->IsSMTP();
// specify main and backup server or localhost / your mail server yourmailserver.com
$mail->Host = "xxx.example.net";
// turn on SMTP authentication
$mail->SMTPAuth = true;
// SMTP username
$mail->Username = "*****#example.net";
$mail->Password = "********"; // SMTP password
//It should be same as that of the SMTP user
$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
//$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = "Admin vueproperty";
$mail->AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
//$mail->AddCC($_POST['email']); // ** Client email
$mail->WordWrap = 50;// set word wrap to 50 characters
$mail->IsHTML(true);// set email format to HTML
$mail->Subject = 'You have mail from: www.exmple.net';
// ** Build the Message
$message = "<h4><b>We received your query</b></h4><br/><br/>";
$message .="Thank you for contacting example.net. A property consultant will be in contact with you asap.<br/>";
$message .="<br>";
$message .="Regards,<br/>";
$message .="The example Team";
$mail->Body = $message;
//header("Location: thank-you.html");
if($mail->Send())
{
$body = "Name: $name<br/>";
$body .= "Phone: $phone<br/>";
$body .= "Email: $visitor_email<br/>";
$mail->AddAddress('xphpxmysql#gmail.com', "MINE");
if($mail->Send()){
header('Location: thank-you.html');
exit;
}
}
}
?>
// ******** Third update
<?
ob_start();
if(isset($_POST['submit']))
{
$title = $_POST['title'];
$name = $_POST['name'];
$surname = $_POST['surname'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$state = $_POST['us'];
$details = $_POST['details'];
$reasons = $_POST['re'];
$content = $_POST['message'];
require("class.phpmailer.php");
$mail = new PHPMailer();
//Your SMTP servers details
// set mailer to use SMTP
$mail->IsSMTP();
// specify main and backup server or localhost / your mail server yourmailserver.com
$mail->Host = "xxx.example.net";
// turn on SMTP authentication
$mail->SMTPAuth = true;
// SMTP username
$mail->Username = "*****#example.net";
$mail->Password = "********"; // SMTP password
//It should be same as that of the SMTP user
$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
//$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = "Admin vueproperty";
$mail->AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
//$mail->AddCC($_POST['email']); // ** Client email
$mail->WordWrap = 50;// set word wrap to 50 characters
$mail->IsHTML(true);// set email format to HTML
$mail->Subject = 'You have mail from: www.exmple.net';
// ** Build the Message
$message = "<h4><b>We received your query</b></h4><br/><br/>";
$message .="Thank you for contacting example.net. A property consultant will be in contact with you asap.<br/>";
$message .="<br>";
$message .="Regards,<br/>";
$message .="The example Team";
$mail->Body = $message;
//header("Location: thank-you.html");
if($mail->Send())
{
$body = "Name: " . $name . "<br/>";
$body .= "Phone: " . $phone . "<br/>";
$body .= "Email: ". $visitor_email . "<br/>";
$mail->body = $body;
$mail->AddAddress('xphpxmysql#gmail.com', "MINE");
if($mail->Send())
{
header('Location: thank-you.html');
exit;
}
}
}
?>
//**** The fifth update
<?
ob_start();
if(isset($_POST['submit']))
{
$title = $_POST['title'];
$name = $_POST['name'];
$surname = $_POST['surname'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$state = $_POST['us'];
$details = $_POST['details'];
$reasons = $_POST['re'];
$content = $_POST['message'];
require("class.phpmailer.php");
$mail = new PHPMailer();
//Your SMTP servers details
// set mailer to use SMTP
$mail->IsSMTP();
// specify main and backup server or localhost / your mail server yourmailserver.com
$mail->Host = "xxx.example.net";
// turn on SMTP authentication
$mail->SMTPAuth = true;
// SMTP username
$mail->Username = "*****#example.net";
$mail->Password = "********"; // SMTP password
//It should be same as that of the SMTP user
$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
//$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = "Admin vueproperty";
$mail->AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
//$mail->AddCC($_POST['email']); // ** Client email
$mail->WordWrap = 50;// set word wrap to 50 characters
$mail->IsHTML(true);// set email format to HTML
$mail->Subject = 'You have mail from: www.exmple.net';
// ** Build the Message
$message = "<h4><b>We received your query</b></h4><br/><br/>";
$message .="Thank you for contacting example.net. A property consultant will be in contact with you asap.<br/>";
$message .="<br>";
$message .="Regards,<br/>";
$message .="The example Team";
$mail->Body = $message;
if($mail->Send())
{
$body = "Name: " . $name . "<br/>";
$body .= "Phone: " . $phone . "<br/>";
$body .= "Email: ". $visitor_email . "<br/>";
$mail->Body = $body;
$mail->AddAddress('xphpxmysql#gmail.com', "MINE");
if($mail->Send())
{
header('Location: thank-you.html');
exit;
}
}
}
?>
//// **** Sixth update NOW it's working it's working
<?
ob_start();
if(isset($_POST['submit']))
{
$title = $_POST['title'];
$name = $_POST['name'];
$surname = $_POST['surname'];
$phone = $_POST['phone'];
$visitor_email = $_POST['email'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$state = $_POST['us'];
$details = $_POST['details'];
$reasons = $_POST['re'];
$content = $_POST['message'];
require("class.phpmailer.php");
$mail = new PHPMailer();
//Your SMTP servers details
// set mailer to use SMTP
$mail->IsSMTP();
// specify main and backup server or localhost / your mail server yourmailserver.com
$mail->Host = "xxx.example.net";
// turn on SMTP authentication
$mail->SMTPAuth = true;
// SMTP username
$mail->Username = "*****#example.net";
$mail->Password = "********"; // SMTP password
//It should be same as that of the SMTP user
$redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
//$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = "Admin vueproperty";
$mail->AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
//$mail->AddCC($_POST['email']); // ** Client email
$mail->WordWrap = 50;// set word wrap to 50 characters
$mail->IsHTML(true);// set email format to HTML
$mail->Subject = 'You have mail from: www.exmple.net';
// ** Build the Message
$message = "<h4><b>We received your query</b></h4><br/><br/>";
$message .="Thank you for contacting example.net. A property consultant will be in contact with you asap.<br/>";
$message .="<br>";
$message .="Regards,<br/>";
$message .="The example Team";
$mail->Body = $message;
$mail->Send();
$mail->ClearAllRecipients();
$body = "Name: " . $name . "<br/>";
$body .= "Phone: " . $phone . "<br/>";
$body .= "Email: ". $visitor_email . "<br/>";
$mail->Body = $body;
$mail->AddAddress('xphpxmysql#gmail.com', "");
if($mail->Send())
{
$mail->ClearAllRecipients();
header('Location: thank-you.html');
exit;
}
}
if i understand exactly your question. you were able to send the email to your client but you want to send it also to you.
if this the case then. add another receptionist$mail->AddAddress($visitor_email, "MY_CLIENT");
EDIT:
first get red of the second line.
if($mail->Send()){$message = "ALL REQUIRED DATA YOU WANT TO SEND TO YOURSELF";$mail->AddAddress('YOUREMAIL#EXAMPLE.COM', "MINE");if($mail->Send()){header('Location: thank-you.html');exit;}}