2010-09-15 104 views
4

這裏我是PHP的新手,我想發送郵件,我的應用程序正在運行,爸爸sahre託管所以請告訴我,我可以實現它。 謝謝大家。在php發送郵件

我收到了你們的回覆,我試過了,但有一些問題。
這是我的代碼..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Send Mail</title> 
</head> 

<body> 
<?php 
     if(isset($_POST['email']) && isset($_POST['subject']) && isset($_POST['msg'])) 
     { 
      $to = $_POST['email']; 
      $subject = $_POST['subject']; 
      $msg = $_POST['msg']; 
      $from = "[email protected]"; 
      $headers = "From: $from"; 
      mail($to,$subject,$msg,$headers); 
      echo "Mail Send"; 
     } 

?> 
<form action="sendMail.php" method="post"> 

<div> 
<table style="width:100%;"> 
<tr> 
<td>Email:</td> 
<td><input type="text" name="email" /></td> 
<td>Subject:</td> 
<td><input type="text" name="subject" /></td> 
</tr> 
    <tr> 
<td>Message</td> 
<td><input type="text" name="msg" /></td> 
<td colspan="2"> <input type="submit" value="Send Mail" /></td> 

</tr> 
</table> 
</div> 
</form> 
</body> 
</html> 

而且運行後此頁我得到了錯誤

"Warning: mail() [function.mail]: SMTP server response: 554 The message was rejected because it contains prohibited virus or spam content in D:\Hosting\5676400\html\myPhp\temp\admin\sendMail.php on line 17" 
+2

www.php.net /manual/en/function.mail.php – 2010-09-15 03:59:39

回答

7

The PHP mail() Function

基本示例:

<?php 
$to = "[email protected]"; 
$subject = "Test mail"; 
$message = "Hello! This is a simple email message."; 
$from = "[email protected]"; 
$headers = "From: $from"; 
mail($to,$subject,$message,$headers); 
echo "Mail Sent."; 
?> 
+0

感謝回覆,我嘗試了你的代碼,但我得到了錯誤信息,在這裏我正在編輯我的問題,我把我的c頌歌和錯誤消息,請看看那裏有什麼問題。再次感謝。 – Abhishek 2010-09-15 04:18:12

+0

錯誤信息是什麼? – ariefbayu 2010-09-15 04:25:57

+0

我認爲你必須提供一些SMTP設置。我發佈了非常基本的例子。您必須根據您的服務器設置提供更多信息。看看這些:** 1。** http://www.phpbuilder.com/board/showthread.php?t=10367822 ** 2。** http://email.about.com/od/emailprogrammingtips/qt /PHP_Email_SMTP_Authentication.htm ** 3。** http://w3schools.invisionzone.com/index.php?showtopic=28584 – NAVEED 2010-09-15 04:27:00

0

請注意,雖然PHP mail()功能非常簡單且使用方便,但計算機操作系統必須能夠自行發送郵件。

你必須檢查返回值mail()(布爾型,如果郵件被接受交付)。

$result = mail(...); 

如果$result變量是,你必須檢查你的電腦郵件配置/實施。

如果是true,並且未發送郵件,則必須檢查計算機郵件日誌。

2

看到一個很好的例子,在這裏發送電子郵件

http://thinkspacetechnologies.com/blog/sending-mails-via-php-script-2/

+0

請注意,只有鏈接的答案是不鼓勵的,所以SO答案應該是搜索的一個終點解決方案(而另一個參考文獻的中途停留時間往往會隨着時間推移而過時)。請考慮在此添加獨立的摘要,並將鏈接保留爲參考。 – kleopatra 2013-07-22 07:33:46

1
<?php 
$message="hi"; 
$to="[email protected]"; 
$sub='Subject of the Mail'; 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
$headers .= "From:[email protected]\r\n"; 
mail($to,$sub,$message,$headers); 
?> 

簡單郵件在PHP發送

這將接受HTML標記,並相應地進行