PHPMailer,SMTP和gmail问题

时间:2019-02-23 05:07:50

标签: php email gmail

所以我制作了一个时间表表单,需要通过SMTP发送。我需要该表格以接收表格条目并将其发送到主电子邮件(办公室经理)和填写时间表的人(员工)。我可以通过mail()函数使用它,但是它们需要文件附件,所以我走了PHPMailer路线。问题是当您从yahoo,gmail或其他第三方服务输入电子邮件时,员工会收到垃圾邮件(如下图所示)。使用我的个人网站电子邮件进行测试时会收到该电子邮件,但是当我使用Gmail电子邮件地址时却不会。如果这是gmail和其他第三方电子邮件服务的安全选项,那真的很糟糕,因为我无法告诉每位员工如何更改其电子邮件设置。但是我认为不是,我认为我做错了什么。我已经附上了php代码。

谢谢您有任何疑问。

<?php
$msg = "";
use PHPMailer\PHPMailer\PHPMailer;
include_once "PHPMailer/PHPMailer.php";
include_once "PHPMailer/Exception.php";
include_once "PHPMailer/SMTP.php";

if (isset($_POST['submit'])) {

//varibles from form
$email = $_POST['email'];
$name = $_POST['employee'];
$date = $_POST['date'];
$jobnum = $_POST['job#'];
$radio = $_POST['radiobtn'];
$customer = $_POST['customer'];
$address = $_POST['location'];
$jobdes = $_POST['jobdescription'];
$starttime = strtotime($_POST['starttime']);
$lunchtime = $_POST['lunch'];
$stoptime = strtotime($_POST['stoptime']);
$totalhours = $_POST['totalhours'];
$drivetime = $_POST['drivetime'];
$notes = $_POST['notes'];
$m1 = $_POST['m-1'];
$m2 = $_POST['m-2'];
$m3 = $_POST['m-3'];
$m4 = $_POST['m-4'];
$m5 = $_POST['m-5'];
$m6 = $_POST['m-6'];
$m7 = $_POST['m-7'];

$q1 = $_POST['q-1'];
$q2 = $_POST['q-2'];
$q3 = $_POST['q-3'];
$q4 = $_POST['q-4'];
$q5 = $_POST['q-5'];
$q6 = $_POST['q-6'];
$q7 = $_POST['q-7'];

$e1 = $_POST['e-1'];
$e2 = $_POST['e-2'];
$e3 = $_POST['e-3'];
$e4 = $_POST['e-4'];
$e5 = $_POST['e-5'];
$e6 = $_POST['e-6'];
$e7 = $_POST['e-7'];

$t1 = $_POST['t-1'];
$t2 = $_POST['t-2'];
$t3 = $_POST['t-3'];
$t4 = $_POST['t-4'];
$t5 = $_POST['t-5'];
$t6 = $_POST['t-6'];
$t7 = $_POST['t-7'];

//HTML EMAIL TABLE WITH FORM DATA ENTRIES
$message = "<html><body>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Tech Name:</strong> </td><td>" .$name. "</td></tr>";
$message .= "<tr><td><strong>Job #:</strong> </td><td>" .$jobnum. "</td></tr>";
$message .= "<tr><td><strong>Date:</strong> </td><td>" . $date . "</td></tr>";
$message .= "<tr><td><strong>Start Time:</strong> </td><td>" . date('h:i a', $starttime) . "</td></tr>";
$message .= "<tr><td><strong>Lunch Duration:</strong> </td><td>" . $lunchtime . "</td></tr>";
$message .= "<tr><td><strong>Stop Time:</strong> </td><td>" . date('h:i a', $stoptime) . "</td></tr>";
$message .= "<tr><td><strong>Total Hours:</strong> </td><td>" . $totalhours . "</td></tr>";
$message .= "<tr><td><strong>Drive Time:</strong> </td><td>" . $drivetime . "</td></tr>";
$message .= "<tr><td><strong>Job Complete:</strong> </td><td>" . $radio . "</td></tr>";
$message .= "<tr><td><strong>Customer:</strong> </td><td>" . $customer . "</td></tr>";
$message .= "<tr><td><strong>Location/Address:</strong> </td><td>" . $address . "</td></tr>";
$message .= "<tr><td><strong>Job Description:</strong> </td><td>" . $jobdes . "</td></tr>";
$message .= "<tr><td><strong>Notes:</strong> </td><td>" . $notes . "</td></tr>";
$message .= "<tr><td><strong>FILE:</strong> </td><td>" . $file . "</td></tr>";
$message .= "<tr><td><strong>Materials:</strong></td> <td><strong>Qty:</strong></td> <td><strong>Each:</strong></td> <td><strong>Total:</strong></td></tr>";
$message .= "<tr><td>$m1</td><td>$q1</td><td>$e1</td><td>$t1</td>";
$message .= "<tr><td>$m2</td><td>$q2</td><td>$e2</td><td>$t2</td>";
$message .= "<tr><td>$m3</td><td>$q3</td><td>$e3</td><td>$t3</td>";
$message .= "<tr><td>$m4</td><td>$q4</td><td>$e4</td><td>$t4</td>";
$message .= "<tr><td>$m5</td><td>$q5</td><td>$e5</td><td>$t5</td>";
$message .= "<tr><td>$m6</td><td>$q6</td><td>$e6</td><td>$t6</td>";
$message .= "<tr><td>$m7</td><td>$q7</td><td>$e7</td><td>$t7</td>";
$message .= "</table>";
$message .= "</body></html>";

//SOMETHING TO DO WITH SENDING A ATTACHMENT???
    if (isset($_FILES['attachment']['name']) && $_FILES['attachment']['name'] != "") {
        $file = "attachment/" . basename($_FILES['attachment']['name']);
        move_uploaded_file($_FILES['attachment']['tmp_name'], $file);
    } else
        $file = "";

    $mail = new PHPMailer();

//set a host
$mail->Host = "mail.gradyelectricforms.com";

//enable SMTP
$mail->isSMTP();

//set authentication to true
$mail->SMTPAuth = true;

//set login details for gmail account
$mail->Username = "forms@gradyelectricforms.com";
$mail->Password = "mypassword";

//set type of protection
$mail->SMTPSecure = "ssl"; // or we can use TLS

//set a port
$mail->Port = 465; //or 587 if TLS

$mail->setFrom($email);
$mail->Subject = "NEW TIMESHEET";
$mail->addAddress('example@123.com');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Body = $message;
$mail->addAttachment($file);

    if ($mail->send())
        $msg = "Your form has been sent, thank you!";
    else
        $msg = "Please try again!";

    unlink($file);
}
?>

Gmail Error Message found in spam

0 个答案:

没有答案
相关问题