是否还有其他要求继续php mailer

问题描述 投票:0回答:1

我像这样在Ubuntu 18.04中安装了phpmailer

composer require phpmailer/phpmailer

将这些功能添加到contactForm.php中

<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
include './../env.php';

require '../vendor/autoload.php';
require '../vendor/phpmailer/phpmailer/src/PHPMailer.php';
require '../vendor/phpmailer/phpmailer/src/SMTP.php';
require '../vendor/phpmailer/phpmailer/src/Exception.php';
//require '../vendor/phpmailer/phpmailer/src/OAuth.php.php';



$mail = new \PHPMailer\PHPMailer\PHPMailer;
$msg_admin=file_get_contents('../mailTemplates/mailAdmin.html');
$msg_client=file_get_contents('../mailTemplates/mailUser.html');
//$mail = new \PHPMailer;

$request_body = file_get_contents('php://input');
$data = json_decode($request_body);

$main_category = $data->main_category;
$user_name = $data->user_name;
$company_name = $data->company_name;
$country_id = $data->country;
$user_address = $data->address;
$email = $data->email;
$contact_no = $data->contact_no;
$description = $data->description;
$headers = '';

<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
include './../env.php';

require '../vendor/autoload.php';
require '../vendor/phpmailer/phpmailer/src/PHPMailer.php';
require '../vendor/phpmailer/phpmailer/src/SMTP.php';
require '../vendor/phpmailer/phpmailer/src/Exception.php';
//require '../vendor/phpmailer/phpmailer/src/OAuth.php.php';



$mail = new \PHPMailer\PHPMailer\PHPMailer;
$msg_admin=file_get_contents('../mailTemplates/mailAdmin.html');
$msg_client=file_get_contents('../mailTemplates/mailUser.html');
//$mail = new \PHPMailer;

$request_body = file_get_contents('php://input');
$data = json_decode($request_body);

$main_category = $data->main_category;
$user_name = $data->user_name;
$company_name = $data->company_name;
$country_id = $data->country;
$user_address = $data->address;
$email = $data->email;
$contact_no = $data->contact_no;
$description = $data->description;
$headers = '';

if
(empty($main_category) || empty($user_name) || empty($user_address) || empty($country_id) || empty($email) || empty($contact_no) || empty($description)) {
    echo json_encode(['success' => false, 'input' => 'invalid']);
} else {

    //Do insert query
    $sql = " INSERT INTO enquiry
 (main_category,user_name,company_name,country_id ,user_address,email,contact_no ,description ) VALUES
  ('" . $main_category . "','" . $user_name . "','" . $company_name . "','" . $country_id . "','" . $user_address . "','" . $email . "','" . $contact_no . "','" . $description . "')";
    if (!mysqli_query($conn, $sql)) {
        echo json_encode(['success' => false,'message' => 'Some thing went wrong']);

    } else {
//        echo json_encode(['success' => true,'message' => 'all ok']);

        $query = mysqli_query($conn,"SELECT enquiry.enquiry_id, MainCategory.name,enquiry.main_category FROM enquiry
        LEFT JOIN MainCategory ON MainCategory.category_id=enquiry.main_category
        ORDER BY enquiry.enquiry_id DESC LIMIT 1 ");
        $result =mysqli_fetch_row($query);

        $msg_admin = str_replace('{{enquiry_id}}', $result[0], $msg_admin);
        $msg_admin = str_replace('{{main_category}}', $result[1], $msg_admin);
        $msg_admin = str_replace('{{name}}', $user_name, $msg_admin);
        $msg_admin = str_replace('{{email}}', $email, $msg_admin);
        $msg_admin = str_replace('{{description}}', $description, $msg_admin);
        //Server settings
        $mail->SMTPDebug =4;                                 // Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.zoho.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = '[email protected]';                 // SMTP username
        $mail->Password = '*************!';  // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port =587;                                    // TCP port to connect to
        //Recipients
        //Admin
        $mail->setFrom($email,$user_name);
        $mail->addAddress('[email protected]','xpl');                 // Add a recipient
        $mail->addReplyTo($email,$user_name);
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'xpl Enquiry';
        $mail->MsgHTML($msg_admin);
        $sent=$mail->send();

        $mail->ClearAllRecipients();
        $mail->ClearReplyTos();
        //$mail->ClearSetFrom();

        //client

        $mail->setFrom('[email protected]','xpl');
        $mail->addAddress($email,$user_name);
        $mail->addReplyTo('[email protected]','xpl');               // Add a recipient
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = 'xpl Enquiry';
        $mail->MsgHTML($msg_client);
        $sent=$mail->send();

        if (!$sent) {
            //   echo "Mailer Error: " . $mail->ErrorInfo;
            echo json_encode( ['success'=>false,'email'=>'Some thing went wrong', $mail->ErrorInfo]);
        } else {

            echo json_encode( ['success'=>true,'email'=>'send success']);
        }

    }
}

错误

以下发件人地址失败:[email protected]:MAIL FROM命令失败,SMTP服务器错误:MAIL FROM命令失败{“成功”:false,“电子邮件”:“某些地方出了问题”,“ 0”:“以下发件人地址失败:[email protected]:MAIL FROM命令失败,SMTP服务器错误:MAIL FROM命令失败SMTP服务器错误:MAIL FROM命令失败“”} 2019-10-28 03:22:20 SMTP通知:检查是否已连接EOF2019-10-28 03:22:20连接:已关闭

邮件验证,env.php是准确的邮件服务器-smtp.zoho.com但是当用户填写他们的查询表格并提交时,我可以看到以上的错误。请有人帮我解决这个问题,谢谢。

php phpmailer production-environment
1个回答
0
投票

这是我工作的phpMailer代码,尽管我使用的是Google邮件服务器,请尝试更改$ mail-> setFrom($ email,$ user_name);到$mail->setFrom("{$email}", "{$user_name}");和$ mail-> addReplyTo($ email,$ user_name);到$mail->addReplyTo("{$email}", "{$user_name}");,我建议现在仅发送一封邮件,以检查每件事是否正常运行

© www.soinside.com 2019 - 2024. All rights reserved.