为什么我的php电子邮件脚本会向我的收件箱中的垃圾邮件发送电子邮件?

时间:2012-08-03 02:57:52

标签: php mysql

以下是我的代码。当我点击“发送电子邮件”按钮它工作正常。但它似乎不在我的收件箱中...它被路由到垃圾邮件文件夹。

<?php require_once "../session.php" ?>
<?php
$host='localhost'; // My hostname
$username='root'; // Mysql username
$password='*********'; // Mysql password
$db_name='jobs'; // DB name

mysql_connect($host, $username, $password)or die("Cannot Connect");
mysql_select_db($db_name);
if (isset($_POST['action']) && $_POST['action'] == "SEND CV NOW") {
$firstname = $_POST['firstname'];
$surname = $_POST['lastname'];
$email = $_POST['email'];

$sql = "SELECT JobTitle,JobID FROM tblebjobs WHERE ID='".$_GET['id']."'";
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
if (!$result) {
        die('Invalid query: ' . mysql_error() . '<br />'. $insertstatement);
} 
$details = mysql_fetch_row($result);

//upload cv first
        if(!isset($_FILES['cv'])) {
            $err = "You forgot to select a CV to upload";
        }       
        $cvname = basename(stripslashes($_FILES['cv']['name']));

        if(empty($cvname)){
            $err = "The name of the attachment was not found.";
        }

        if(empty($err)){
            $newcv = "tempcv/".$cvname;
            $result = @move_uploaded_file($_FILES['cv']['tmp_name'], $newcv);
                if(empty($result)){
                    $err = "There was an error moving the uploaded cv please try again if it continues to file please call us directly.";
                } else {
                    //increment by 1
                    $sql3 = "update `emp_record` set `total_app`=`total_app` + 1 WHERE username='".$_SESSION['name']."'";
                    $result3 = mysql_query($sql3) or die ("Could not insert data into DB: " . mysql_error());
                    $sql2 = "update `tblebjobs` set `total_app`=`total_app` + 1 WHERE ID='".$_GET['id']."'";
                    $result2 = mysql_query($sql2) or die ("Could not insert data into DB: " . mysql_error());

                    //create random for boundry
                    $random_hash = md5(date('r', time())); 
                    //set email headers
                    $headers = "Return-path: <".$email.">"."\r\n";
                    $headers .= "Reply-to: <".$email.""."\r\n";
                    $headers .= "Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"\r\n";
                    $headers .= "From: ".$email." <".$email.">"."\r\n";
                    $headers .= "X-Priority: 3\r\n";
                    $headers .= "X-Mailer: E-borders.net web site\r\n";
                    $headers .= "MIME-Version: 1.0\r\n";
                    $headers .= "\r\n\r\n";
                    //setup message and include $body previously prepped
                    $prebody = "--PHP-mixed-{$random_hash}\r\n";
                    $prebody .="Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
                    $prebody .="Content-Transfer-Encoding: 7bit\r\n";
                    $prebody .="\r\n";
                    $prebody .="A CV has been submitted from the website the CV is attached to this email and the details of the form submission are below.<br /><br />";
                    $prebody .="{$firstname} {$surname}<br />";
                    $prebody .="{$email}<br />";
                    $prebody .="\r\n";
                    $prebody .="--PHP-mixed-{$random_hash}\r\n";
                // prep attachments
                    $data = chunk_split(base64_encode(file_get_contents($newcv)));
                    $prebody .= "Content-Type: application/pdf; name=\"{$newcv}\"\r\n";
                    $prebody .= "Content-Disposition: attachment; filename=\"{$newcv}\"\r\n";
                    $prebody .= "Content-Transfer-Encoding: base64\r\n\r\n";
                    $prebody .= "{$data}\r\n\r\n";
                    $prebody .= "--PHP-mixed-{$random_hash}\r\n";
                    $prebody .= "\r\n";     
                    //set to address
                    $to  = 'jtcompanero@yahoo.com';
                    //set subject
                    $subject = "CV FROM: {$details[0]} ({$details[1]})";
                    // Mail it
                    mail($to, $subject, $prebody, $headers);
                    unlink($newcv);
                    $err = "Your CV has been submitted we will be in touch shortly";
                }
        }
}
?>

<u><strong>Apply Online</strong></u>
<?php if (isset($err)) {
    echo "<div style=\"text-align:center;color:red;font-weight:bold;\">$err</div>";
}?>
<p>
<form method="POST" action="apply.php?id=<?php echo $_GET['id'];?>" enctype="multipart/form-data">
<table border="0" cellpadding="5" cellspacing="0" align="center">
<tr><td>First name:</td><td><input type="text" name="firstname" id="firstname"></td></tr>
<tr><td>Last name:</td><td><input type="text" name="lastname" id+"lastname"></td></tr>
<tr><td>Email Address:</td><td><input type="text" name="email" id="email"></td></tr>
<tr><td>Path to CV:</td><td><input type="file" name="cv" id="cv" /></td></tr>
</table>
<p align=center>
<input type="submit" name="action" id="action" value="SEND CV NOW">
</p>
</form>
</p>
</div>

另外......我在这里有简历附件。但该文件也没有添加到消息中。

1 个答案:

答案 0 :(得分:1)

它与您的电子邮件内容有关(在正文中或在标题内)。不是真正的PHP代码本身。

垃圾邮件过滤器以不同的方式工作,因此无法为您提供特定的解决方案。

注意:尝试使用http://swiftmailer.org/等邮件组件发送电子邮件,而不是使用大字符串构建它们。