Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-26-2013, 02:17 PM   PM User | #1
bluefrog1974
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
bluefrog1974 is an unknown quantity at this point
Send email to a variable?

Hi I'm using the standard phpmailer class with the smtp class and this handler:

Code:
<?
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");
}
?>
What I'm trying to do is replace $mail->AddAddress("email address to send to", "Name"); with $mail->AddAddress(EMAIL NAME I WANT TO EMAIL);

I've tried:

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

and nothing seems to work, I keep getting an error;

Message could not be sent.
Mailer Error: Language string failed to load: recipients_failed

Any help?

I'm trying to use the form to email my clients when I need to from my admin backend, the name and email are stored as variables of $contact_name & $contact_email

So the form will work in reverse, instead of sending all emails from them to me as a normal form would work, it will send them from me based on which client is loaded to their email address.

so not: me@me.com instead you@you.com so you receive the email and I dont.
bluefrog1974 is offline   Reply With Quote
Old 01-26-2013, 03:11 PM   PM User | #2
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
This should work:
PHP Code:
$mail->AddAddress($contact_email,"Subject Of The Email"); 
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Users who have thanked Redcoder for this post:
bluefrog1974 (01-26-2013)
Old 01-26-2013, 04:11 PM   PM User | #3
bluefrog1974
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
bluefrog1974 is an unknown quantity at this point
Thank you so much, that worked brilliantly. I made a slight modification so I don't need to call the variable file:

Code:
$mail->AddAddress($_POST['email'],"Subject Of The Email");
All working perfectly.
bluefrog1974 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:31 AM.


Advertisement
Log in to turn off these ads.