php - PhpMailer - Is sending message but not pulling the form data -
this question has answer here:
i have tried make simple php contact form, turned out needed use smtp , phpmailer because it's hosted on windows server. have set contact form using example document on phpmailer website. having trouble pulling data form. email send in body shows as:
> name: $name > > email: $email > > message: $comment i know there lots of questions on here stackoverflow, can't seem figure out.
php
<?php require 'phpmailer/phpmailerautoload.php'; $name = $_request['name']; $email = $_request['email']; $comment = $_request['comment']; $mail = new phpmailer; $mail->smtpdebug = 2; // enable verbose debug output $mail->issmtp(); // set mailer use smtp $mail->host = 'mail.example.co.uk'; // specify main , backup smtp servers $mail->smtpauth = false; // enable smtp authentication $mail->username = 'test@example.co.uk'; // smtp username $mail->password = 'password'; // smtp password $mail->smtpsecure = 'tls'; // enable tls encryption, `ssl` accepted $mail->port = 25; // tcp port connect $mail->from = 'test@example.co.uk'; $mail->fromname = 'mailer'; $mail->addaddress('test@example.co.uk', 'bob'); // 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 = 'here subject'; $mail->body = '<p><strong>name:</strong> $name</p> <p><strong>email:</strong> $email</p> <p><strong>message:</strong> $comment</p>'; $mail->altbody = 'this body in plain text non-html mail clients'; if(!$mail->send()) { echo 'message not sent.'; echo 'mailer error: ' . $mail->errorinfo; } else { echo 'message has been sent'; } ?> html
<form role="form" method="post" action="mail.php"> <p><label for="name">name</label></p> <p><input type="text" id="name" name="name" placeholder="first & last name" value=""></p> <p><label for="subject" >subject</label></p> <p><input type="text" id="subject" name="subject" placeholder="subject" value=""></p> <p><label for="email" >email</label></p> <p><input type="email" id="email" name="email" placeholder="example@domain.com" value=""></p> <p><label for="comment">message</label></p> <p><textarea rows="4" id="comment" name="comment"></textarea></p> <p><input id="submit" name="submit" type="submit" value="send"></p> </form>
your code $mail->body is:
$mail->body = '<p><strong>name:</strong> $name</p> <p><strong>email:</strong> $email</p> <p><strong>message:</strong> $comment</p>'; $mail->altbody = 'this body in plain text non-html mail clients'; just replace below code :
$mail->body = '<p><strong>name: </strong>'.$name.'</p> <p><strong>email: </strong>'.$email.'</p> <p><strong>message: </strong>'.$comment.'</p>'; $mail->altbody = ' body in plain text non-html mail clients';
Comments
Post a Comment