Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

How to reverse email?

the mail() function

Moderators: macek, egami, gesf

How to reverse email?

Postby bluefrog » Thu Jan 24, 2013 8:31 am

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?

Code: Select all
<?
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 :)
bluefrog
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Jan 24, 2013 6:21 am

Return to PHP coding => Mail

Who is online

Users browsing this forum: Google [Bot] and 10 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.