2014-04-10 100 views
0

我一直在研究這個,但不能得到答案。 我有一個表單將信息發送到我的數據庫,我也希望信息轉到存儲在數據庫中的表中的列中的電子郵件地址。繼承人的代碼,我只是玩弄,看看我可以做一個SELECT查詢,但它wouldnt工作,也Iknow,在發送電子郵件的作品時,我手動UT斯達康一個地址到我的「setTo」將表格信息發送到存儲在數據庫中的電子郵件

require 'mail/class.simple_mail.php'; 
$mailer = new SimpleMail(); 

$comments = $_REQUEST['comments']; 
$time = $_REQUEST['time']; 
$date = $_REQUEST['date']; 
$place = $_REQUEST['place']; 
$email = "SELECT email FROM bridesmaids"; 

$message = "<strong>This is an email from the bride to you the bridesmaids, here is the information on the next dress fitting<br />".$date." ".$time." ".$place." ".$comments." </strong>"; 



$send = $mailer->setTo('$email', 'Your Email') 
       ->setSubject('Dress Fitting') 
       ->setFrom('[email protected]', 'Domain.com') 
       ->addMailHeader('Reply-To', '[email protected]', 'Domain.com') 
       ->addMailHeader('Cc', '[email protected]', 'Bill Gates') 
       ->addGenericHeader('Content-Type', 'text/html; charset="utf-8"') 
       ->setMessage($message) 
       ->setWrap(100) 
       ->send(); 
echo ($send) ? 'Your Email has been sent to your bridesmaids' : 'Could not send email'; 
+1

變量不會在單引號下解析,您需要刪除它們。寫這樣的..'$發送= $郵件程序 - > setTo($電子郵件,'您的電子郵件')' –

+0

好吧,謝謝你的迴應,但我不認爲我的SELECT查詢選擇表中的enails工作,有任何想法嗎? – user3464354

+0

你不能直接使用你的SELECT查詢作爲你的$ email變量 –

回答

0

你不不會在數據庫中查詢實際的電子郵件地址。你只是有一個包含SQL查詢的字符串,但你從來沒有真正連接到數據庫並使用查詢獲取數據。

$email = "SELECT email FROM bridesmaids"; 

這應該成爲這樣的事情:

$mysqli = new mysqli("localhost", "my_user", "my_password", "world"); 
if ($result = $mysqli->query("SELECT email FROM bridesmaids")) { 
    printf("Select returned %d rows.\n", $result->num_rows); 
    $result->close(); 
} 
+0

謝謝你,但是我作爲我的setTo做了什麼呢? – user3464354

1

如果您還沒有創建一個SQL連接,這樣做第一則:

1:從你的伴娘選擇你的電子郵件表 - 然後將結果返回到數組(PDO::FETCH_ASSOCfetch_array(MYSQLI_ASSOC))並將此數組綁定到變量,例如$mailingList

2:包裝你郵包代碼在foreach環路(http://uk3.php.net/manual/en/control-structures.foreach.php)的示例將是:

foreach($mailingList as $value) { 

    // your mailer code here, replace $email with $value 
    $send = $mailer->setTo($value, 'Your Email') 
    // $value will update for each iteration with your emails 

} 

3:確保其不需要重複任何代碼或變量的外循環。

+0

$值不應該在單引號那裏:'$ mailer-> setTo($ value,'您的電子郵件')' – Cagy79

+0

道歉,只是複製了原來的問題,將更新 –

相關問題