2014-02-09 172 views
0

我有發送電子郵件的代碼到我的郵箱PHP不能發送電子郵件

,但如果我按OK我收到無法發送電子郵件至* *@hotmail.com

我的Linux服務器上運行( Fedora的),而我不不更改任何設置

我mail.html文件

<html> 
<head><title>Mail sender</title></head> 
<body> 
<form action="mail.php" method="POST"> 
<b>Email</b><br> 
<input type="text" name="email" size=40> 
<p><b>Subject</b><br> 
<input type="text" name="subject" size=40> 
<p><b>Message</b><br> 
<textarea cols=40 rows=10 name="message"></textarea> 
<p><input type="submit" value=" Send "> 
</form> 
</body> 
</html> 

和我email.php文件是:

<html> 
<head><title>PHP Mail Sender</title></head> 
<body> 
<?php 

# Retrieve the form data 
$email  = $_POST['email']; 
$subject = $_POST['subject']; 
$message = $_POST['message']; 

# Sends mail and report success or failure 
if (mail($email,$subject,$message)) { 
    echo "<h4>Thank you for sending email</h4>"; 
} else { 
    echo "<h4>Can't send email to $email</h4>"; 
} 
?> 
</body> 
</html> 

請儘量幫我

+0

你是不是想從本地主機發送電子郵件?如果是的話,然後檢查以下鏈接http://stackoverflow.com/questions/4595730/sending-email-from-localhost –

+0

@ManishGoyal我嘗試它,但同樣的結果 – user3264926

回答

0

最佳,如果您使用專用腳本用於發送電子郵件。如PHPMailer它給你的各種配置選項,包括SMTP:

// Send Mail 
$mail = new PHPMailer(); // initiate 
$mail->IsSMTP(); // use SMTP 

// SMTP Configuration 
$mail->SMTPAuth = true; // set SMTP 
$mail->Host = "myhost"; // SMTP server 
$mail->Username = "[email protected]"; 
$mail->Password = "password";    
$mail->Port = 465; // change port is required 
+0

我怎樣才能得到用戶名和密碼爲smtp – user3264926

+0

這是從你的服務器。如果您從SMTP服務器發送電子郵件,則這些將是該電子郵件帳戶的用戶名和密碼。您也可以選擇不使用SMTP。查看PHPMailer示例並查看哪一個最適合您 - http://phpmailer.worxware.com/index.php?pg=examples – malta