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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts

    phpmailer script

    I am a complete idiot when it comes to mail scripts. Let alone the popular phpmailer script.

    I downloaded the script, found the "code generator" in the examples, and found a script that works (TLS/smtp) and copied the code. I directed my form to it, and it does nothing. It just goes to the php file, and prints it out like text. That's it, as far as I can tell. I'm just going to start from scratch, because all the tutorials out there have made no sense to me.

    My Form:
    Code:
    <form method="post" name="$500-offer_PPC-google" action='PHPMailer-master/examples/mailscript.php' id="form141" ><br/>
    <input type="text" id="firstName" name="firstName" value="" placeholder="First Name"><br/>
    <input type="text" id="lastName" name="lastName" value="" placeholder="Last Name"><br/>
    <input type="text" id="email" name="email" value="" placeholder="Email">
    <input type="text" id="company" name="company" value="" placeholder="company"><br/>
    <input type="text" id="emailAddress" name="emailAddress" value="" placeholder="email"><br/>
    
    <input type="submit" value="Submit" name="submit">
    
    </form>

    Script (The included phpMailerAutoloader.php script I have not edited from the original):

    Code:
    require_once '../PHPMailerAutoload.php';
     
    $results_messages = array();
     
    $mail = new PHPMailer(true);
    $mail->CharSet = 'utf-8';
     
    class phpmailerAppException extends phpmailerException {}
     
    try {
    $to = 'myname@website.com';
    if(!PHPMailer::validateAddress($to)) {
      throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!");
    }
    
    
    $first_name_field = $_POST['firstName'];
    $last_name_field = $_POST['lastName'];
    $elq_campaign_id = $_POST['elqCampaignId'];
    $company = $_POST['company'];
    $businessPhone = $_POST['businessPhone'];
    $email_field = $_POST['emailAddress'];
    
    
    $mail->isSMTP();
    $mail->SMTPDebug  = 0;
    $mail->Host       = "smtp.hostname.com";
    $mail->Port       = "25";
    $mail->SMTPSecure = "tls";
    $mail->SMTPAuth   = true;
    $mail->Username   = "myname@website.com";
    $mail->Password   = "123123123";
    $mail->addReplyTo("myname@website.com", "name");
    $mail->From       = $email_field;
    $mail->FromName   = "name";
    $mail->addAddress("myname@website.com", "myself");
    $mail->Subject  = "test(PHPMailer test using SMTP)";
    $body = <<<'EOT'
    Test email
    $first_name_field $last_name_field
    $elq_campaign_id
    $company
    $businessPhone
    
    EOT;
    $mail->WordWrap = 80;
    $mail->msgHTML($body, dirname(__FILE__), true); //Create message bodies and embed images
    $mail->addAttachment('images/phpmailer_mini.gif','phpmailer_mini.gif');  // optional name
    $mail->addAttachment('images/phpmailer.png', 'phpmailer.png');  // optional name
     
    try {
      $mail->send();
      $results_messages[] = "Message has been sent using SMTP";
    }
    catch (phpmailerException $e) {
      throw new phpmailerAppException('Unable to send to: ' . $to. ': '.$e->getMessage());
    }
    }
    catch (phpmailerAppException $e) {
      $results_messages[] = $e->errorMessage();
    }
     
    if (count($results_messages) > 0) {
      echo "<h2>Run results</h2>\n";
      echo "<ul>\n";
    foreach ($results_messages as $result) {
      echo "<li>$result</li>\n";
    }
    echo "</ul>\n";
    }

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,093
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Dumb question but seeing as you say the php prints like text..

    Do you have <?php at the beginning of the file and ?> at the end? - You've not shown this in your php code.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    turpentyne (11-11-2013)

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts
    nooooooooooooooooo!!!

    ok. That is officially one of my most embarassing moments in coding. I copy-pasted the code and didn't once think about that.



    ok... problem solved. moving on to the next challenge

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,093
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by turpentyne View Post
    That is officially one of my most embarassing moments in coding.
    Don't worry too much, we've all done daft things in the past.

    I have many times
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

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