php - Using PHPMailer if form submits -


i'm trying run phpmailer if form submitted. i've tried few different ways no success.

i'm not sure part of code sends email. when test using

if(!$mail->send()) {     echo 'message not sent.';     echo 'mailer error: ' . $mail->errorinfo; } else {     echo 'message has been sent'; }  

it works, know runs correctly. ideas why code doesn't work?

<?php      require_once 'c:\wamp\www\phpmailer\phpmailer-master\phpmailerautoload.php';      $mail = new phpmailer;     //$mail->smtpdebug = 3;                               // enable verbose debug output      $mail->issmtp();                                      // set mailer use smtp     $mail->host       = 'smtp.gmail.com   ';  // specify main , backup smtp servers     $mail->smtpauth   = true;                               // enable smtp authentication     $mail->username   = 'test@gmail.com';                 // smtp username     $mail->password   = 'password';                           // smtp password     $mail->smtpsecure = 'tls';                            // enable tls encryption, `ssl` accepted     $mail->port       = 587;                                    // tcp port connect      $mail->setfrom('from@example.com', 'mailer');     $mail->addaddress('tester@gmail.com', 'marco');     // add recipient     //$mail->addaddress('ellen@example.com');               // name optional     //$mail->addreplyto('info@example.com', 'information');     //$mail->addcc('cc@example.com');     //$mail->addbcc('bcc@example.com');      $mail->addattachment('/var/tmp/file.tar.gz');         // add attachments     $mail->addattachment('/tmp/image.jpg', 'new.jpg');    // optional name     $mail->ishtml(true);                                  // set email format html      $mail->subject = 'new application';     $mail->body    = "--personal information-- first name: $fname middle name: $mname last name: $lname address:$address city:$city state:$state zip:$zip ";      //$mail->altbody = 'this body in plain text non-html mail clients';  if (isset($_post['submit']))     { $mail->send();     } ?> 

if test isset($_post['submit']) failing either means submit param not provided, or it's present null value. hazard of using isset rather more accurate check array_key_exists('submit', $_post).

also why check presence of param late? check earlier can skip other phpmailer code that's not going used.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -