2016-08-12 80 views
-2

是否有必要在其中的網站使用代碼的郵件ID?它顯示郵件已發送,但不會向代碼中提到的mailid發送任何內容。並且我懷疑哪個emailid,郵件將被髮送?爲此,我要在我的域上創建一個ID?PHP代碼發送郵件

$msg=" ".$a." ".$b." ".$c." ".$d." ".$e; 
$to="[email protected]"; 
$sub=$a; 
$msg = wordwrap($msg, 70); 
#echo $msg; 

$r=mail($to,$sub,$msg); 

    if($r== true) { 
echo"<script>alert('mailsent');</script>"; 
    }else { 
     echo"<script>alert('failure');</script>"; 
    } 

我用的代碼:使用電子郵件()發送電子郵件

the code i hav used

+0

你認爲「emailid」是什麼?這個問題沒有意義。 –

+0

歡迎來到Stack Overflow! [請不要將您的代碼作爲圖像發佈。](// meta.stackoverflow.com/q/285551) – FrankerZ

+0

[PHP郵件表單不能完成發送電子郵件](http:// stackoverflow。 com/questions/24644436/php-mail-form-doesnt-complete-sending-e-mail) – FrankerZ

回答

1

是靠不住的,充其量,你不知道,如果該電子郵件被實際發送或不喜歡你已經發現將郵件傳遞給郵件會增加郵件發送的機會。

$headers = "From: $email\r\n"; 
$headers .= "Reply-To: $email\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 

if(mail($to, $sub, $msg, $headers)){ 
    echo "<p>Email Sent</p>"; 
} 

一個更好的辦法是使用PHPMailer的 - https://github.com/PHPMailer/PHPMailer

這裏是他們的發送郵件的樣本

require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

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

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 

$mail->setFrom('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 

的PHPMailer是非常靈活,可以用很少的選項一起使用,也可以配置爲使用SMTP,然後電子郵件可以通過身份驗證帳戶發送,甚至可以使用第三方電子郵件服務(如SendGrid)來發送和監控您的電子郵件。 https://sendgrid.com/