PHP Mailer shows no errors but doesn't send the email - php

I'm creating a booking form as a favour but have decided to send mail via the domain, not the server. This is mainly for better security and less limits in responses and data transfers.
I've been working on this for the last few days and trying to teach myself how to get it to work. I now have a very simple working example which can be seen here below.
This is the simple booking form:
<form method="post" name="process.php" action="process.php">
<p>Name:</p><br><input type="text" name="name"><br><br>
<p>Email Address:</p><br><input type="email" name="email"><br><br>
<br>
<input type="submit" name="submit" value="Send Email">
Then in process.php I have this working code:
<?php
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['submit']))
{
// Values need to be santiised
$name = $_POST['name']; //Name of the person requesting a booking
$email = $_POST['email']; //Email of the person requesting a booking
require '../vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'test#handler.net';
$mail->Password = '[PASSWORD]';
$mail->setFrom('test#handler.net'); // All emails would be sent from the handler.net domain to the bookings email of the other domain. (Using test to test, will be noreply)
$mail->addAddress('bookings#salon.com'); // Recipient of the email should be the bookings address, this won't change.
$mail->addReplyTo($email); // The reply to address will be the email address of the user who submitted the booking enquiry.
$mail->addBCC('outbox#handler.net'); // This is to keep a record of all emails that have been sent. Responses will also be saved to a CSV file.
$mail->Subject = 'Booking Request'; // Subject of the email sent to bookings#salon.com that the form responses will be contained within.
$mail->isHTML(TRUE);
$mail->Body = 'Booking request from '.$name.' with email '.$email; // Shows the salon the form response via the email and when they reply a new thread should start in order to compose a new email to reply to the email of the form submitter.
if(!$mail->send()) { // Send the email.
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
}
?>
The code above works and sends the emails from the right address, to the right address. That was on a site in public_html/testing and has been moved to a different site in public_html/booking so the relative paths will be the same. The only files within this directory are index.php (the form) and send.php (the process file with confirmation message)
For some reason this new code with all of the form values will not send. I'm honestly not too sure as to why it won't work now so any pointers at all would be massively appreciated.
<?php
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['submit']))
{
// Values need to be santiised
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$service = $_POST['service'];
$date = $_POST['date'];
$time = $_POST['time'];
require '../vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'noreply#handler.net';
$mail->Password = '[PASSWORD]';
$mail->setFrom('Handler | Bookings'); // Emails sent via Noreply.
$mail->addAddress('bookings#salon.com'); // Email form responses sent to bookings#salon.com
$mail->addReplyTo($email); // Reply to the user who submitted the form.
$mail->addBCC('outbox#handler.net'); // Store record of all emails sent via the system.
$mail->Subject = 'Booking Request'; // Subject of the email sent to bookings#salon.com that the form responses will be contained within.
$mail->isHTML(TRUE);
$mail->Body = '
Booking request from '.$forename.' with email '.$email;'
Test Values: $forename $surname $email $phone $service $date $time
if(!$mail->send()) { // Send the email.
echo '';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo '';
}
}
?>
I don't need the echo statements at the end, I just need the email to send following this sort of format:
<img src="https://via.placeholder.com/300x150" width="15%">
<p><b>Name:</b> $forename $surname</p>
<p><b>Email:</b> $email</p>
<p><b>Phone:</b> $phone</p>
<p><b>Service:</b> $service</p>
<p><b>Date:</b> $date</p>
<p><b>Time:</b> $time</p>
I'm just not sure why the emails now will not send when they have done before. Any pointers would be appreciated.
UPDATE
Here's the updated code with the progress made with thanks to Mr Perfect
<?php
mail("bookings#salon.com", "test", "message");
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['submit']))
{
// Values need to be santiised
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$service = $_POST['service'];
$date = $_POST['date'];
$time = $_POST['time'];
$message = <<<DELIMETER
<img src="https://via.placeholder.com/300x150" width="15%">
<p><b>Name:</b> {$forename} {$surname}</p>
<p><b>Email:</b> {$email}</p>
<p><b>Phone:</b> {$phone}</p>
<p><b>Service:</b> {$service}</p>
<p><b>Date:</b> {$date}</p>
<p><b>Time:</b> {$time}</p>
DELIMETER;
require '../vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 3;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'noreply#handler.com';
$mail->Password = '[PASSWORD]';
$mail->setFrom('Handler | Bookings'); // Emails sent via Noreply.
$mail->addAddress('bookings#salon.com','ADMIN'); // Email form responses sent to bookings#salon.com.
$mail->addReplyTo($email); // Reply to the user who submitted the form.
// $mail->addBCC('outbox#handler.net'); // Store record of all emails sent via the system.
$mail->Subject = 'Booking Request | SUBMISSION'; // Subject of the email sent to bookings#salon.com that the form responses will be contained within.
$mail->isHTML(TRUE);
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->send()) { // Send the email.
echo '';
echo '' . $mail->ErrorInfo; // I don't need to echo any errors because the submission page has the text above already.
} else {
echo '';
}
}
?>

You should look at your $mail->addAdress, $mail->addBCC and $mail->addReplyTo fields and follow the correct syntax for those fields.
Test the code below.
<?php
use PHPMailer\PHPMailer\PHPMailer;
if(isset($_POST['submit']))
{
// Values need to be santiised
$forename = $_POST['forename'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$service = $_POST['service'];
$date = $_POST['date'];
$time = $_POST['time'];
require '../vendor/autoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Host = 'smtp.hostinger.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'test#handler.net';
$mail->Password = '[PASSWORD]';
$mail->setFrom('test#handler.net','Bookings'); // Emails sent via Noreply.
$mail->addAddress('bookings#salon.com',''); // Email form responses sent to bookings#salon.com
$mail->addReplyTo($email,$forename.' '.$surname); // Reply to the user who submitted the form.
$mail->addBCC('outbox#handler.net',''); // Store record of all emails sent via the system.
$mail->Subject = 'Booking Request'; // Subject of the email sent to admin#handler.net that the form responses will be contained within.
$mail->isHTML(TRUE);
$mail->Body = <<<EOD
Booking request from {$forename} with email {$email}.<br />
Contact details: <br />
Full name: {$forename} {$surname}<br />
Email: {$email} <br />
Phone number: {$phone} <br />
Service: {$service} <br />
Date: {$date} {$time}
EOD;
if(!$mail->send()) { // Send the email.
echo '';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo '';
}
}
?>

This block of code is wrong, some quotes are missing
$mail->Body = '
Booking request from '.$forename.' with email '.$email;'
Test Values: $forename $surname $email $phone $service $date $time
To enable variable replacement on a string use double quotes, and you won't need to concatenate variables with dot(.), also this make possible to use escaped caracters like \n, try to adjust your code like this:
$mail->Body = "Booking request from $forename with email $email\n" .
"Test Values: $forename $surname $email $phone $service $date $time";

Firstly we have to view the error so therefore you have to set
$mail->SMTPDebug = 0;
into
$mail->SMTPDebug = 3;
So you can get that error to post against that error.

Related

Which PHPMailer prop controls the sender email in the email header?

I'm getting an error from jQuery with a 404 to my mail.php (I checked the path and it seems correct)
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require("../includes/libraries/phpmailer/PHPMailer-master/src/Exception.php");
require("../includes/libraries/phpmailer/PHPMailer-master/src/PHPMailer.php");
require("../includes/libraries/phpmailer/PHPMailer-master/src/SMTP.php");
$server_email = 'myemail#outlook.com';
$pass = '123456';
$full_name = $_POST['full_name'];
$email = $_POST['email'];
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp-mail.outlook.com';
$mail->Port = 587;
$mail->Username = $server_email;
$mail->Password = $pass;
$mail->FromName = $full_name;
$mail->From = $email;
$mail->setFrom($server_email, $full_name );
$mail->addAddress($server_email);
$mail->addReplyTo($email); //email that it will be replied to
$mail->Subject = 'Subscription submitted by ' . $full_name . '.';
$mail->Body = "
Name: $full_name<br><br>
Email: $email<br>
";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message has been sent";
}
?>
Right now, my email (the outlook one) comes up in the header of the email next to the Sender's Name. The addReplyTo actually does give me the gmail address to reply to, so that's great. But having my email show on the sender header is confusing. See the image below
Thanks in advance

How to addCC and addReplyTo for multiple email addresses?

I'd like to use this send.php script for a contact form. Right now when an email is sent, a user inputs their name, email, and the email of the person to send the email to.
The email is sent from #Email_Placeholder and both #Email_Placeholder, $email, and #email_2 gets a copy of the email.
I'd like to add the option for an addReplyTo and addCC so that both $email and $email_2 receives an email when either of the 3 parties makes a reply to the original email thread.
What is the correct syntax so that $email, and $email_2 are added to the addReplyTo and addCC parameters so that they receive every email in the original thread?
//Lines to edit. Goal add $email and $email_2 to addReplyTo and addCC
$mail->addReplyTo('#Email_Placeholder', 'Information');
$mail->addCC('#Email_Placeholder'); //should be changed to the name of the app owner's email
Send.php
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING); //sanitize data
$email = filter_var($_POST['email'], FILTER_SANITIZE_STRING);
$email_2 = filter_var($_POST['email_2'], FILTER_SANITIZE_STRING);
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
/*added line of code*/
if(empty($name)){
header("location: index.php?nouser");
exit();
}
if(empty($email)){
header("location: index.php?noemail");
exit();
}
if(empty($message)){
header("location: index.php?noemail");
exit();
}
/*if(empty($message)){
header("location: index.php?nomessage");
exit();
}//end validation*/
//added line; 'honeypot'
if(empty($_POST['phone2'])){
//Information that needs to be filled out to be able to send an email through phpmailer
//Will use an SMTP service. SMTP is basically like a mail server to send mail
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 1;
//$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = false;
$mail->Host = 'relay-hosting.secureserver.net';
$mail->Port = "25";
$mail->Username = "#Email_Placeholder";
$mail->Password = "Password";
$mail->SetFrom("#Email_Placeholder");
$mail->setFrom('#Email_Placeholder', 'Greeting');
// Add a recipient : used to also send to name
//This sends an email to both $email and $email_2
$mail->addAddress($email);
$mail->addAddress($email_2);
//This makes it so that #Email_Placeholder receives a copy of the emails
$mail->addReplyTo('#Email_Placeholder', 'Information');
$mail->addCC('email#gmail.com');
/*$mail->addBCC('bcc#example.com');*/
//Body content
$body = "<p><strong>Hello, </strong>" . $email . " How are you?
<br>
<b> Please Notice: </b><br>
<br> <br> Your message was Delivered: " . $message . ". Hello" . $name2 .
"</p>";
$mail->isHTML(true);
//subject line of email
$mail->Subject = $name;
//for html email
$mail->Body = $body;
$mail->AltBody = strip_tags($body);
//the email gets sent
header("Location: http://www.test-domain.com");
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>

PHP Mailer - Receiving Spam Emails

I have a website with a "book appointment" section which requires all fields to be completed before sending an email. Since the website is relatively popular, we get many requests during the day. I am using PHPMailer to receive e-mails.
Unfortunately, some of the email I receive are in this format:
A client has made a request to book an appointment.
Client Name: 5c3a5beb89e89
Client Email: sbethdddany5996#gmail.com
Client Number:
Message:
The e-mail is a spam email. How can I avoid this? The following is my PHP script.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$msg = $_POST['msg'];
require 'phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "***";
$mail->SMTPSecure = "tsl";
$mail->Port = ***;
$mail->SMTPAuth = true;
$mail->Username = '***';
$mail->Password = '***!';
$mail->setFrom($email, $totalName);
$mail->addAddress('***');
$mail->Subject = "Appointment Request";
$mail->Body = "A client has made a request to book an apointment.
\n\nClient Name: $name \n\nClient Email: $email \n\nClient Number: $phone \n\nMessage: $msg";
if ($mail->send()){
header('Location: index.html');
}
else{
echo "Something went wrong, please try again.";
}
?>

How to Code phpMailer to prevent sending email if hidden field is filled in contact form

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'];
...
}

Replacing mail() script with SMTP script [closed]

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;}}

Categories