2014-04-16 2 views
-2

PHP로 이메일을 보내려고하지만받는 사람이 내 데이터베이스에 저장된 이메일이되도록하고 싶습니다. 여기 데이터베이스에 저장된 주소로 php로 이메일 보내기

는 여기에 몇 가지 코드

$send = $mailer->setTo('[email protected]', 'Your Email') 
       ->setSubject('Example') 
       ->setFrom('[email protected]', 'test') 
       ->addMailHeader('Reply-To', '[email protected]', 'test') 
       ->addMailHeader('Cc', '[email protected]', 'test') 
       ->addGenericHeader('Content-Type', 'text/html; charset="utf-8"') 
       ->setMessage($message) 
       ->setWrap(400) 
       ->send(); 

하는 형태에서, 그 떠난를 전송되고있는 이메일 인 사용자는 당신은 당신의 데이터베이스를 조회 할 필요가

mysql_select_db("lr", $con); 
require 'mail/class.simple_mail.php'; 
$mailer = new SimpleMail(); 

$comments = $_REQUEST['comments']; 
$time = $_REQUEST['time']; 
$date = $_REQUEST['date']; 
$place = $_REQUEST['place']; 

$message = "<strong>This is an email from the bride to you the bridesmaids, here is the information on the next dress fitting<br />Date:".$date."<br />Time: ".$time."<br /> Place:".$place."<br />Any other comments: ".$comments." </strong>"; 
if ($send) {echo 'Your Email has been sent';}else { 
echo 'An error occurred. We could not send email'; 
+0

그래, 이메일을 보낼 수있는 코드가 있습니다. 데이터베이스에 연결하고 쿼리하는 코드가 있습니까? –

+1

우선 유효한 데이터를 넣고 테스트 해보십시오. 그것은 이미 메일 발송 프로세스가 잘 작동하는지 여부를 나타냅니다. 그런 다음 데이터베이스에서 데이터를 가져 오기위한 코드를 작성해야합니다. 해당 코드가 붙어 있다면 그냥 돌아와서 우리에게 보여 주어 우리가 도울 수 있도록하십시오. –

+0

네, 테스트 해 보았습니다. 실제로 입력 된 이메일을 보낼 때 작동합니다. – user3464354

답변

2

채 웁니다. mysqli에 대한 튜토리얼 http://www.w3schools.com/php/php_ref_mysqli.asp

당신은 다음과 같은 것이 필요할 것이다.

$qry = "SELECT email FROM users WHERE username = ?'" 
$stmt = $mysqli->prepare($qry); 
$stmt->bind_param('s', 'someone'): 
$stmt->execute(); 
$stmt->bind_result($email); 

그리고 나서 $ email을 setTo 매개 변수에 넣으십시오.

이 자습서가 실제로 더 좋습니다. http://codular.com/php-mysqli

관련 문제