web-dev-qa-db-ja.com

PHP mail()を介して送信されるメールがスパムにならないようにするにはどうすればよいですか?

PHPのmail()関数を使用してメールを送信しています(sendmailプロセスが実行されています)。ただし、すべてのメールはスパムになります(Gmailの場合)。ネット上で見つけた多くのトリックを試しましたが、どれも機能していません。確実なトリックについて教えてください。

32
Partyboy

針ヘッダーを追加する必要があります。

サンプルコード:

$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "Return-Path: [email protected]\r\n";
$headers .= "CC: [email protected]\r\n";
$headers .= "BCC: [email protected]\r\n";

if ( mail($to,$subject,$message,$headers) ) {
   echo "The email has been sent!";
   } else {
   echo "The email has failed!";
   }
?> 
37
user744116

確実なショットのトリックはありません。メールがスパムとして分類される理由を調べる必要があります。 SpamAssassinには 正当な送信者が誤検知を避けるためのヒント を説明するページがあります。 コーディングホラー:メールを送信したい(コードを使用)

18
Oswald
<?php

$subject = "this is a subject";
$message = "testing a message";




  $headers .= "Reply-To: The Sender <[email protected]>\r\n"; 
  $headers .= "Return-Path: The Sender <[email protected]>\r\n"; 
  $headers .= "From: The Sender <[email protected]>\r\n";  
  $headers .= "Organization: Sender Organization\r\n";
  $headers .= "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
  $headers .= "X-Priority: 3\r\n";
  $headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;



mail("[email protected]", $subject, $message, $headers); 


?> 
4
Ahmed Medhat

PHPメーラーライブラリ を試してください。
または、SMTP経由でメールを送信すると、送信前にフィルタリングされます。
また、FROMreturn-path

4
Rikesh
$fromMail = 'set your from mail';
$boundary = str_replace(" ", "", date('l jS \of F Y h i s A'));
$subjectMail = "New design submitted by " . $userDisplayName;


$contentHtml = '<div>Dear Admin<br /><br />The following design is submitted by '. $userName .'.<br /><br /><a href="'.$sdLink.'"><b>Click here</b></a> to check the design.</div>';
$contentHtml .= '<div><a href="'.$imageUrl.'"><img src="'.$imageUrl.'" width="250" height="95" border="0" alt="my picture"></a></div>';
$contentHtml .= '<div>Name : '.$name.'<br />Description : '. $description .'</div>';

$headersMail = '';
$headersMail .= 'From: ' . $fromMail . "\r\n" . 'Reply-To: ' . $fromMail . "\r\n";
$headersMail .= 'Return-Path: ' . $fromMail . "\r\n";
$headersMail .= 'MIME-Version: 1.0' . "\r\n";
$headersMail .= "Content-Type: multipart/alternative; boundary = \"" . $boundary . "\"\r\n\r\n";
$headersMail .= '--' . $boundary . "\r\n";
$headersMail .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headersMail .= 'Content-Transfer-Encoding: base64' . "\r\n\r\n";
$headersMail .= rtrim(chunk_split(base64_encode($contentHtml)));

try {
    if (mail($toMail, $subjectMail, "", $headersMail)) {
        $status = 'success';
        $msg = 'Mail sent successfully.';
    } else {
        $status = 'failed';
        $msg = 'Unable to send mail.';
    }
} catch(Exception $e) {
    $msg = $e->getMessage();
}

これは私にとってはうまく機能します。画像とリンクを含むメールが含まれ、あらゆる種類のメールIDで機能します。手がかりは、すべてのヘッダーを完全に使用することです。

Localhostからテストする場合は、確認する前に以下を設定します。

ローカルホストからのメール送信を設定する方法xampp:

  1. D:/xampp/sendmail/sendmail.iniのすべてにコメントし、以下に言及する

    [送信]

    smtp_server = smtp.gmail.com smtp_port = 587 error_logfile = error.log debug_logfile = debug.log [email protected] auth_password = your-mail-password [email protected]

  2. D:/xampp/php/php.iniでa。下

    [メール機能]

    SMTP = smtp.gmail.com smtp_port = 587

b。 sendmail_from = [email protected] cを設定します。 sendmail_pathのコメントを外します= "\" D:\ xamp\sendmail\sendmail.exe\"-t"したがって、以下のようになります。

sendmail_path = "\"D:\xamp\sendmail\sendmail.exe\" -t"

d。コメントsendmail_path = "D:\ xamp\mailtodisk\mailtodisk.exe"したがって、以下のようになります。

;sendmail_path="D:\xamp\mailtodisk\mailtodisk.exe"

e。 mail.add_x_header=Off

0
Ipsita Rout
<?php 
$to1 = '[email protected]';
$subject = 'Tester subject'; 

    // To send HTML mail, the Content-type header must be set

    $headers .= "Reply-To: The Sender <[email protected]>\r\n"; 
    $headers .= "Return-Path: The Sender <[email protected]>\r\n"; 
    $headers .= "From: [email protected]" ."\r\n" .
    $headers .= "Organization: Sender Organization\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=utf-8\r\n";
    $headers .= "X-Priority: 3\r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
?>
0
SAVe