2016-04-29 1 views
-1

私はPHPプロジェクトに取り組んでいます。私はユーザーにメールを送るはずです。私はPHP関数mail()を使用することに決めました。いつでも、私は以下のコードを試し、それが失敗した:WAMPとsendmailを使ってローカルでメールを送ることができません

// Sending the confirmation mail 
 

 
      $confirmation_link = "http://localhost/africafashion_newversion/confirm.php?id=$user_id&token=$token"; 
 

 
      $to = $_POST['email']; 
 
      $subject = "Confirmation de votre compte"; 
 

 
      $message = ' 
 
       <html> 
 
        <head> 
 
         <title>'.$subject.'</title> 
 
        </head> 
 

 
        <body> 
 
         <div> 
 

 
          <table cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse;margin:0;padding:0;font-family:Arial,Helvetica,sans-serif;width:100%!important;height:100%!important"> 
 
           <tbody> 
 
            <tr> 
 
             <td align="center" style="padding-bottom:20px;border-collapse:collapse"> 
 
              
 
              <img src="logo.png" alt="Stack Exchange" style="width:180px;min-height:43px; padding:30px 0; text-align: center;outline:none;" /> 
 

 
              
 
              <div style="max-width:400px; margin: 0 auto; border:1px solid #eee;border-radius:3px;background:#ffffff; padding: 25px 10px;"> 
 
                 
 
               <p>You are almost done!</p> 
 

 
               <p><a href="'.$confirmation_link.'" style="color:#15c; text-decoration: none;">Click here to complete your registration</a></p> 
 

 
              </div> 
 
              
 
              <div style="font-size:95%; color:#999;font-family: Helvetica,Arial,sans-serif"> 
 
               
 
               <p> 
 
                Questions? Comments? Let us know on our <a href="#" style="color:#15c; text-decoration: none;">feedback site</a>. 
 
               </p> 
 

 
               <p> 
 
                Stack Exchange Inc. 110 William Street, 28th floor, NY NY 10038 
 
               </p> 
 

 
              </div> 
 
             </td> 
 
            </tr> 
 
           </tbody> 
 
          </table> 
 

 
         </div> 
 
        </body> 
 
       </html> 
 
      '; 
 

 
      // Always set content-type when sending HTML email 
 
      $headers = "MIME-Version: 1.0" . "\r\n"; 
 
      $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
 

 
      // More headers 
 
      $headers .= 'From: <[email protected]>' . "\r\n"; 
 
      $headers .= 'Cc: [email protected]' . "\r\n"; 
 

 
      if (mail($to,$subject,$message,$headers)) { 
 
       
 
       $_SESSION['flash']['success'] = 'A mail has been successfully sent.'; 
 

 
       header('Location: login.php'); 
 
       exit(); 
 

 
      }else{ 
 

 
       $_SESSION['flash']['danger'] = "Confirmation mail not sent"; 
 

 
       $req = $pdo->prepare('DELETE FROM users WHERE UserID = ?'); 
 

 
       $req->execute([$user_id]); 
 

 
       header('Location: register.php'); 
 
       exit(); 
 
      } 
 

 
     }

私はこの問題を解決する助けてください。

+0

のコードは、あなたがメールを送信可能にするためにはまだすべての構成設定を行ったことがありますか? (これはWindowsマシン上では提供されていないためです)。ユーザーのコメントには、その達成方法に関するヒントがあります。 http://php.net/manual/en/function.mail.php#118210 – CBroe

+0

私は8時間前にメールを送りましたが、HTML形式のメールを実装した後、そのエラーが発生しています。その欠陥は 'sendmail'からのものではない – Prince

答えて

0

SendMailは使用しないでください。SwiftMailerを使用できます。それはあなただけでなく、受信トレイで電子メールを送ることができます(スパムとしてではなく.. !!!)。それはあなたを助け、あなたの時間を節約します。

私Send.php

include_once "inc/swift_required.php"; 

$subject = 'Hello from Jeet Patel, PHP!'; //this will Subject 
$from = array('[email protected]' =>'mydomain.com'); //you can use variable 

$text = "This is TEXT PART"; 
$html = "<em>This IS <strong>HTML</strong></em>"; 

$transport = Swift_SmtpTransport::newInstance('abc.xyz.com', 465, 'ssl'); 
$transport->setUsername('[email protected]'); 
$transport->setPassword('*********'); 
$swift = Swift_Mailer::newInstance($transport); 



    $to = array($row['email'] => $row['cname']); 
    $message = new Swift_Message($subject); 
    $message->setFrom($from); 
    $message->setBody($html, 'text/html'); 
    $message->setTo($to); 
    $message->addPart($text, 'text/plain'); 

    if ($swift->send($message, $failures)) 
    { 
     echo "Send successfulllyy"; 
    } else { 
     print_r($failures); 

    } 
関連する問題