forms - Php Mailer / GoDaddy -


i uploaded contact form page attachment option coded in html embedded php (contact.php) via godaddy, when want fill out form , submit it, lot of errors don't understand.

i using php mailer , php include php page (bootstrap.php) contact page.

below code:

contact page:

<!doctype html> <html> <head>    <?php         ini_set('display_errors', 'on');         error_reporting(e_all);        include('bootstrap.php');    ?> </head> <body>    <div class = "wrapper">           <section class ="bulk">            <?php if(isset($_get["status"]) == "thanks") { ?>                 <br><br><br><br><br><br><br><br><br><br><br><br>                 <p class = "text-center"> email! in touch shortly </p>                 <?php } else { ?>                     <h1 class = "text-center">                       forward working you!                     </h1><br>                                         <h4 class = "text-center" style="font-weight:normal;">                         please complete form , attach file                     </h4>                 <!-- form stuff -->                                                              <div class ="row">                                                 <div class="contact">                                                                                                                                                           <form method ="post" action ="contact.php" enctype='multipart/form-data'>                                 <div class="form-group">                                    <label for="name">name</label>                                     <input type ="text" class="form-control" name="name" id ="name" placeholder="enter name" value="<?php if (!empty($_post['name'])) {echo $_post['name'];} ?>">                                                                                <?php                                          if ($error) {                                             echo "<p class='text-danger'>$errname</p>";                                         }                                         else {                                             echo "<br>";                                         }                                                                                ?>                                 </div>                                                                                                                                                                                                          <!--email-->                                 <div class="form-group">                                     <label for="email">email</label>                                     <input type ="text" class="form-control" name="email" id ="email" placeholder="enter email" value="<?php if (!empty($_post['email'])) {echo $_post['email'];} ?>">                                     <?php                                          if ($error) {                                             echo "<p class='text-danger'>$erremail</p>";                                         }                                         else {                                             echo "<br>";                                         }                                                                                ?>                                 </div>                                    <!--msg-->                                 <div class="form-group">                                     <label for="message">message</label>                                                                                 <textarea name ="message" class="form-control" id ="message" placeholder="enter message" rows = "10" ></textarea>                                     <?php                                          if ($error) {                                             echo "<p class='text-danger'>$errmessage</p>";                                         }                                         else {                                             echo "<br>";                                         }                                                                                ?>                                 </div>                                  <!--attachments-->                                 <div class="form-group">                                     <label for="attachment" >attach file</label>                                                                                 <input type ="file" name='attachment' id='attachment'>                                 </div>                                 <!--hpam sponypot -->                                 <div class="form-group" style="visibility: hidden">                                          <label for="address">address</label>                                     <input type ="text" name="address" id ="address">                                       <p> humans, not fill out form! </p>                                 </div>                                                                      <!--attachments-->                                 <div class = "buttons"> </div><button type="submit" value="send" class="button">submit</button>                         </form>                     </div><br><br>                     </div>                      <?php } ?>             </section>   

and php page (bootstrap.php) included on top of contact page:

require_once("phpmailer/class.phpmailer.php"); require_once('phpmailer/phpmailerautoload.php'); $mail = new phpmailer();  // variable declarations  $errname = ''; $erremail = ''; $errmessage = ''; $error = false;   if ($_server["request_method"] == "post") { $name = trim($_post["name"]); //trim destroys whitespaces "tab" or  "spacebar" $email = trim($_post["email"]); $phonenumber = trim($_post["phonenumber"]); $message = trim($_post["message"]);  // attack #1 preventor - spam honeypot  if ($_post["address"] != "") {     echo "spam honeypot";     exit; }  // attack #2 preventor - email header injection hack preventor   foreach($_post $value) {     if(stripos($value, 'content-type:') !== false) {         echo "there problem information entered.";         exit;     } }   // check if name has been entered if ($name == "") {     $errname = 'sorry, have not entered name, please try again.';              }  // check if message has been entered if ($message == "") {           $errmessage = 'sorry, have not typed message.';       }  // check if email valid if (!$mail->validateaddress($email)) {             $erremail = 'sorry, please enter valid email address.'; }  // flag error messages if tests fail  if ($errname || $errmessage || $errphonenumber || $erremail) {     $error = true; // boolean flag validating error messages in html }  else {                    // email body iff form validation successfull!      $email_body = "";     $email_body = $email_body. "name: " . $name . "<br>";     $email_body = $email_body. "email: " . $email . "<br>";     $email_body = $email_body. "phone number: " . $phonenumber . "<br>";     $email_body = $email_body. "message: " . $message;       date_default_timezone_set('etc/utc');       //tell phpmailer use smtp     $mail->issmtp();      //enable smtp debugging     // 0 = off (for production use)     // 1 = client messages     // 2 = client , server messages     $mail->smtpdebug = 2;      //ask html-friendly debug output     $mail->debugoutput = 'html';      //set hostname of mail server     $mail->host = 'smtp.gmail.com';      //set smtp port number - 587 authenticated tls, a.k.a. rfc4409 smtp submission     $mail->port = 465;      //set encryption system use - ssl (deprecated) or tls     $mail->smtpsecure = 'ssl';      //whether use smtp authentication     $mail->smtpauth = true;      //username use smtp authentication - use full email address gmail     $mail->username = "#############################";      //password use smtp authentication     $mail->password = "###################";      //set message sent     $mail->setfrom($email, $name);      //set message sent     $mail->addaddress('companyname@gmail.com', 'company name');      //set subject line     $mail->subject = 'phpmailer gmail smtp test';      //add attachment     $mail->addattachment($_files['attachment']); //        if (isset($_files['attachment']) && //            $_files['attachment']['error'] == upload_err_ok) { //            $mail->addaddress($_files['attachment']['tmp_name'], //                                 $_files['attachment']['name']); //        }       //read html message body external file, convert referenced images embedded,     //convert html basic plain-text alternative body     $mail->msghtml($email_body);       //send message, check errors     if (!$mail->send()) {         echo "mailer error: " . $mail->errorinfo;     }     else {                  }     header("location: contact.php?status=thanks");     exit; } } ?> 

these error messages come when submitting form:

notice: array string conversion in   /home/username/public_html/phpmailer/class.phpmailer.php on line 2395 not access file: array server -> client: 220-n1plcpnl0057.prod.ams1.secureserver.net esmtp exim 4.85                  #2 thu, 07 jan 2016 07:46:23 -0700 220-we not authorize use of       system          transport unsolicited, 220 and/or bulk e-mail. client -> server: ehlo mywebsite.com server -> client: 250-n1plcpnl0057.prod.ams1.secureserver.net hello       n1plcpnl0057.prod.ams1.secureserver.net [46.252.205.183]250-size 52428800250-      8bitmime250-pipelining250-auth plain login250-starttls250 client -> server: starttls server -> client: 220 tls go ahead client -> server: ehlo mywebsite.com server -> client: 250-n1plcpnl0057.prod.ams1.secureserver.net hello       n1plcpnl0057.prod.ams1.secureserver.net [46.252.205.183]250-size 52428800250-     8bitmime250-pipelining250-auth plain login250 client -> server: auth login server -> client: 334 xxx client -> server: iymjiymjiymjiymjiymjiymjiymjiymjiymjiym= server -> client: 334 xxx client -> server: iymjiymjiymjiymjiymjiymjiw== server -> client: 535 incorrect authentication data smtp error: password command failed: 535 incorrect authentication data smtp error: not authenticate. client -> server: quit server -> client: 221 n1plcpnl0057.prod.ams1.secureserver.net closing     connection smtp connect() failed.      https://github.com/phpmailer/phpmailer/wiki/troubleshooting mailer error: smtp connect() failed.      https://github.com/phpmailer/phpmailer/wiki/troubleshooting warning: cannot modify header information - headers sent (output      started @ /home/myusername/public_html/contact.php:4) in      /home/username/public_html/bootstrap.php on line 148 

the code in line 148 of bootstrap.php

header("location: contact.php?status=thanks"); 

thanks help.

your problem passing whole $_files['attachment'] array addattachment() method in first parameter , not string containing filepath. hence error message!

this path location of file in $_files['attachment']['tmp_name'] have not moved uploaded file tmp storage permanant file location.

parameter 2 while optional passed if wish , can found in $_files['attachment']['name']

so amend piece of code this

//add attachment $mail->addattachment($_files['attachment']['tmp_name'],                      $_files['attachment']['name']); 

the prototype method is:

public function addattachment($path,                               $name = '',                               $encoding = 'base64',                               $type = 'application/octet-stream') 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -