Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    333
    Thanks
    2
    Thanked 47 Times in 46 Posts
    This should work:
    PHP Code:
    $mail->AddAddress($contact_email,"Subject Of The Email"); 

  • Users who have thanked Redcoder for this post:

    bluefrog1974 (01-26-2013)

  • #3
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •