Jump to content

Reverse email


bluefrog

Recommended Posts

Hi I have a script (below) which is for a standard email form. However, I would like to be able to use it to email people instead, I know it's just a case of setting the $mail->AddAddress to the details of the user I'm mailing (set in a variable of $contact_email) but I can't seem to get it right.

 

I've tried the following:

 

$mail->AddAddress($contact_email);

$mail->AddAddress = $contact_email;

$mail->AddAddress $_POST['email']; (taken from the html form)

 

Any idea's?

 

<?
ob_start();
if(isset($_POST['btnSubmit']))
{
require("class.phpmailer.php");


$mail = new PHPMailer();


//Your SMTP servers details


$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "mydetails"; // specify main and backup server or localhost
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "mydetails"; // SMTP username
$mail->Password = "mydetails"; // SMTP password
//It should be same as that of the SMTP user


$redirect_url = "redirectdetails" ; //.$_SERVER['SERVER_NAME']; //Redirect URL after submit the form


$mail->From = $mail->Username; //Default From email same as smtp user
$mail->FromName = "test User";


$mail->AddAddress("email address to send to", "Name"); //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 = "Hi[name]".$_POST['fullname']." \r\n <br>Email Adrress :".$_POST['email']." \r\n <br> \r \n".$_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");
}
?>

 

Thanks in advance :)

Link to comment
https://forums.phpfreaks.com/topic/273607-reverse-email/
Share on other sites

Have you tried it with 2 params (email, name)?

 

In the code you pasted it shows as:

 

$mail->AddAddress("email address to send to", "Name");

 

So try:

 

$mail->AddAddress("[email protected]", "First Last");

 

If that works then try your $POST variables with email and fullname

Link to comment
https://forums.phpfreaks.com/topic/273607-reverse-email/#findComment-1408050
Share on other sites

@Kingy, yeah I did think of that but it kept giving the error of string failed, please supply email address. I echoe'd the string being passed and it was correct.

 

@BigGrecian, so if I replace the "$mail->AddAddress("email address to send to", "Name");" to "$to = '[email protected]';" is there anything on the form or elsewhere on this form I will need to change? I'm using the standard smtp classes.

 

Oh and thank you very much both, I'm new to php and it's driving me nuts lol

Link to comment
https://forums.phpfreaks.com/topic/273607-reverse-email/#findComment-1408134
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.