bluefrog Posted January 24, 2013 Share Posted January 24, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/273607-reverse-email/ Share on other sites More sharing options...
Kingy Posted January 24, 2013 Share Posted January 24, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/273607-reverse-email/#findComment-1408050 Share on other sites More sharing options...
BigGrecian Posted January 24, 2013 Share Posted January 24, 2013 You need to use the $to = '[email protected]'; Quote Link to comment https://forums.phpfreaks.com/topic/273607-reverse-email/#findComment-1408057 Share on other sites More sharing options...
bluefrog Posted January 25, 2013 Author Share Posted January 25, 2013 (edited) @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 Edited January 25, 2013 by bluefrog Quote Link to comment https://forums.phpfreaks.com/topic/273607-reverse-email/#findComment-1408134 Share on other sites More sharing options...
bluefrog Posted January 27, 2013 Author Share Posted January 27, 2013 Solved this myself like this: $mail->AddAddress($_POST['email'],"Subject Of The Email"); Thanks for all your help though Quote Link to comment https://forums.phpfreaks.com/topic/273607-reverse-email/#findComment-1408515 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.