0

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

?>
programcode
  • 104
  • 1
  • 14

0 Answers0