2014-03-14 127 views
-1
$to = '[email protected]'; 
$subject = 'Feedback'; 
$finalmessage = ""; 
$from = '[email protected]'; 

$finalmessage = $name . $address . $phnum . $email . $feedback; 
$finalmessage = wordwrap($finalmessage, 70); 

$mail=mail($to,$subject,$finalmessage,"From: $from\n"); 

if($mail){ 
    echo "Thank you for using our mail form"; 
}else{ 
    echo "Mail sending failed."; 
} 

那就是代碼。最後顯示「感謝您使用我們的郵件表單」,但我沒有收到任何郵件。任何想法最新怎麼了?PHP郵件功能不起作用?

+2

您使用它在本地? –

+0

可能是服務器配置問題。你有沒有看到右邊的所有鏈接--->?其中一個肯定有你的答案。你不是第一個有這個問題的人。 – Floris

+0

你應該使用它在一個託管(可以freehosting)如http://www.000webhost.com使其工作。你應該參考這個代碼,http://sysaxiom.com/php/email_system.php –

回答

0

您需要在php.ini文件來配置你的本地服務器的SMTP設置如下:

[mail function] 
; For Win32 only. 
SMTP = localhost // your smtp server 
smtp_port = 25 

或者你應該給嘗試Swift MailerPHP Mailer

+0

已經試過 – rancour86

+0

已經試過,但沒有運氣 – rancour86

+0

你在哪個電子郵件地址發送電子郵件。因爲有可能從你的學校服務器傳出電子郵件被阻止 –

0

使用PHP郵件()函數

您可以使用PHPmailer: http://phpmailer.codeworxtech.com/

否w^ 使用下面的代碼 -

 <?php 
     require("class.phpmailer.php"); // give proper path of folder if needed 
     $mail = new PHPMailer(); 

     session_start(); 
     ob_start(); 
     php?> 

     <your mail body goes here> 



     <?php 
     $body=ob_get_contents(); 
     ob_end_clean(); 
     $to = '[email protected]'; 
     $subject = 'Feedback'; 
     $finalmessage = ""; 
     $from = '[email protected]'; 

     $finalmessage = $name . $address . $phnum . $email . $feedback; 
     $finalmessage = wordwrap($finalmessage, 70); 
     $mail->Host = "mail.yourdomain.com"; // SMTP server 
     $mail->IsHTML(true); 
     $mail=mail($to,$subject,$finalmessage,"From: $from\n"); 

     if($mail){ 
     echo "Thank you for using our mail form"; 
     }else{ 
     echo "Mail sending failed."; 
     } 
+0

我知道,但仍然無法弄清楚這個代碼有什麼問題? – rancour86

+0

你的代碼是好的...但服務器不支持郵件發送...所以我想你必須使用phpmailer –

0

您需要配置您的郵件的SMTP在php.ini 這是很簡單的,你有什麼ISP?例如,Comcast公司,剛剛在谷歌「康卡斯特SMTP地址和端口」

採取注意SMTP地址和端口的搜索,然後去你的php.ini此配置 搜索:

[mail function] 
; For Win32 only. 
SMTP = localhost // your smtp server 
smtp_port = 25 

使用SMTP和smtp_port更改地址。然後,你應該能夠發送電子郵件在本地主機

+0

已經嘗試過 – rancour86

1

如果(isset($ _ POST [ '提交'])){

$to="email"; 
// this is your Email address 
$from = $_POST['Email_Address']; // this is the sender's Email address 
$first_name = $_POST['Full_Name']; 
$tel_num=$_POST['Telephone_Number']; 
$msg=$_POST['Your_Message']; 
$subject = "Full Name : ".$first_name; 

$headers = "From: ".$first_name." <".$from.">\r\n"; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 

$message="Full Name : ".$first_name."<br><br>Telephone Number : ".$tel_num."<br><br>Message : ".$msg; 

$bericht = nl2br($message); 

mail($to,$subject,$message,$headers); 



}