shams Posted August 4, 2018 Share Posted August 4, 2018 I want to send mail with phpmailer using form index.php and mailer.php the variables from $_POST is working, the "print_r($_POST);" prints all the values of variables from the form to the mailer.php: Array ( [name] => shamsurrahman [from] => shams@example.com [email] => shams@example.net [cc] => [bcc] => [subject] => test message [message] => test message from phpmailer. [submit] => Submit ) Something weird happened The mail cannot send and in the /var/log/php.log these are errors: [04-Aug-2018 00:27:52 UTC] PHP Notice: Undefined variable: error in /var/www/pmailer/index.php on line 14 [04-Aug-2018 00:27:52 UTC] PHP Notice: Undefined variable: Name in /var/www/pmailer/index.php on line 18 [04-Aug-2018 00:27:52 UTC] PHP Notice: Undefined variable: From in /var/www/pmailer/index.php on line 22 [04-Aug-2018 00:27:52 UTC] PHP Notice: Undefined variable: Email in /var/www/pmailer/index.php on line 26 [04-Aug-2018 00:27:52 UTC] PHP Notice: Undefined variable: CC in /var/www/pmailer/index.php on line 31 [04-Aug-2018 00:27:52 UTC] PHP Notice: Undefined variable: BCC in /var/www/pmailer/index.php on line 35 [04-Aug-2018 00:27:52 UTC] PHP Notice: Undefined variable: Subject in /var/pmailer/index.php on line 40 [04-Aug-2018 00:27:52 UTC] PHP Notice: Undefined variable: Message in /var/www/pmailer/index.php on line 44 [04-Aug-2018 00:27:54 UTC] Call to undefined method PHPMailer\PHPMailer\PHPMailer::setFromName() This is mailer.php: <?php set_exception_handler(function($e) { error_log($e->getMessage()); exit('Something weird happened'); //something a user can understand }); error_reporting(E_ALL); ini_set('display_errors', '1'); use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; require 'vendor/phpmailer/phpmailer/src/Exception.php'; require 'vendor/phpmailer/phpmailer/src/PHPMailer.php'; require 'vendor/phpmailer/phpmailer/src/SMTP.php'; $mail = new PHPMailer(true); $From = $_POST['from']; $Name = $_POST['name']; $Email = $_POST['email']; $Subject = $_POST['subject']; $Message = $_POST['message']; $CC = $_POST['cc']; $BCC = $_POST['bcc']; print_r($_POST); try { //Server settings $mail->SMTPDebug = 2; $mail->isSMTP(); $mail->Host = 'localhost'; $mail->SMTPAuth = false; $mail->Port = 25; //Recipients $mail->AddReplyTo("$Email"); $mail->setFrom($From); $mail->setFromName($Name); $To = "$Email"; $mail->addAddress($To); $mail->addCC($CC); $mail->addBCC($BCC); //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject($Subject); $mail->Body($Message); $mail->AltBody($Message); $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; } ?> Any help please? Quote Link to comment Share on other sites More sharing options...
shams Posted August 4, 2018 Author Share Posted August 4, 2018 Hi i did some modification in form index.php and rename to index.html now it is some thing improved now the only problem is with the Subject and Body i can send the message with: $mail->Subject = 'test message'; $mail->Body = 'test message from phpmailer'; But with the variable from the form : $mail->Subject($Subject); $mail->Body($Message); Get this error: [04-Aug-2018 04:50:09 UTC] Call to undefined method PHPMailer\PHPMailer\PHPMailer::Subject() any help please? Quote Link to comment Share on other sites More sharing options...
benanamen Posted August 4, 2018 Share Posted August 4, 2018 You really dont see the problem huh? Look at what works and what doesn't. It's right in front of you. Quote Link to comment Share on other sites More sharing options...
shams Posted August 4, 2018 Author Share Posted August 4, 2018 Thanks for reply, please can tell me how to post the Subject and Body in variables from the form to the mailer.php? Quote Link to comment Share on other sites More sharing options...
shams Posted August 4, 2018 Author Share Posted August 4, 2018 The problem solved with the: $mail->Subject = $_POST['subject']; $mail->Body = $_POST['message']; $mail->AltBody = $_POST['message']; Quote Link to comment Share on other sites More sharing options...
benanamen Posted August 4, 2018 Share Posted August 4, 2018 The actual problem was you were creating/calling functions/methods that do not exist. $mail->Subject($Subject) ; $mail->Body($Message); It should have been $mail->Subject = $Subject ; $mail->Body = $Message; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.