Jump to content

Problem sending mail with PHPmailer?


shams

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.