php项目邮件连接无效,php - 无法访问此项目(PHP邮件) - SO中文参考 - www.soinside.com...

当我尝试提交完成的表格时,它必须将我重定向到成功页面,以指示电子邮件已成功发送。但不幸的是,这出现了,并且电子邮件没有收到image site

这是代码<?php

use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\Exception;

require 'PHPMailer-master/src/Exception.php';

require 'PHPMailer-master/src/PHPMailer.php';

require 'PHPMailer-master/src/SMTP.php';

// Instantiation and passing [ICODE]true[/ICODE] enables exceptions

$mail = new PHPMailer(true);

try {

function get_ip() {

if(isset($_SERVER['HTTP_CLIENT_IP'])) {

return $_SERVER['HTTP_CLIENT_IP'];

}

elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {

return $_SERVER['HTTP_X_FORWARDED_FOR'];

}

else {

return (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '');

}

}

//Server settings

$ip=get_ip();

$query=@unserialize(file_get_contents('http://ip-api.com/php/'.$ip));

$mail->SMTPDebug = 2; // Enable verbose debug output

$mail->isMail(); // Set mailer to use SMTP

$mail->Host = 'smtp.office365.com'; // Specify main and backup SMTP servers

$mail->SMTPAuth = true; // Enable SMTP authentication

$mail->Username = '//'; // SMTP username

$mail->Password = '///'; // SMTP password

$mail->SMTPSecure = 'tls'; // Enable TLS encryption, [ICODE]ssl[/ICODE] also accepted

$mail->Port = 587; // TCP port to connect to

$ips=$_SERVER['REMOTE_ADDR'];

$name = $_POST['name'];

$email = $_POST['email'];

$mobile = $_POST['mobile'];

$landline = $_POST['landline'];

$date = $_POST['date'];

$people = $_POST['people'];

$lunch = $_POST['lunch'];

$enquiry = $_POST['enquiry'];

$questions = $_POST['questions'];

//Recipients

$mail->setFrom($email, $name);

$mail->addAddress('bookings@rios.com.au', 'Rios bookings'); // Name is optional

$mail->addAddress($email, $name); // Add a recipient

$mail->addReplyTo('bookings@rios.com.au', 'Information from customer');

// $mail->addCC('cc@example.com');

// $mail->addBCC('bcc@example.com');

// // Attachments

// $mail->addAttachment('/home/cpanelusername/attachment.txt'); // Add attachments

// $mail->addAttachment('/home/cpanelusername/image.jpg', 'new.jpg'); // Optional name

// Content

// $mail->isHTML(true); // Set email format to HTML

$mail->Subject = 'Rio E-mail from Website / Contact Us Form';

$mail->Body = "

New Message from Rio Contact Form

Name: {$name}

Email: {$email}

Mobile: {$mobile}

Landline: {$landline}

Date: {$date}

People: {$people}

Lunch or Dinner: {$lunch}

Enquiry or booking: {$enquiry}

Questions: {$questions}

{$ips} {$query['city']} {$query['regionName']} {$query['zip']} {$query['timezone']}

";

header('location:success.html');

$mail->send();

echo 'Message has been sent';

} catch (Exception $e) {

echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";

}

这是我整理文件的方式files

...................................................... ....................................]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值