1

データが php/mySQL クエリからのものである電子メールを送信したいと考えています。

html が電子メールに表示されることはわかっていますが、php コードは表示されないと思います。

mySQL DB からクエリされたコンテンツを含むメールを送信する方法はありますか?

私はすでにここで検索しています。それをカバーするトピックが1つありますが、アドバイスした人は、私の場合は適用できないpdfエクスポートまたはサードパーティツールを使用することを提案しました。

みんな助けてくれてありがとう:)

4

2 に答える 2

2

PHPMailerを使用して、サーバー上で電子メールを生成します。マルチパート メッセージ (添付ファイルと埋め込み/インライン イメージを含むプレーンテキスト + html) を非常に簡単に生成できます。基本的:

// set up PHPMailer
$mail = new PHPMailer();
$mail->SetFrom('you@yourserver.com');
$mail->AddReplyTo('you@somewhereelse.com');
$mail->Subject('Your profile');
$mail->IsHTML(TRUE);

// do your database query
$con = connect_to_database();
$stmt = run_database_query($con, "SELECT ... FROM ...");

$data = fetch_from_database($stmt);


// set the email address
$mail->AddAddress($data['email'], $data['fullname']);


// html content for smart email clients
$html = <<<EOL
<h1>Welcome</h1>

<p>Your username is {$data['username']}.</p>
EOL;

// plain text alternate content
$text = <<<EOL
Welcome

Your username is {$data['username']}.
EOL;

// add the content to the mail
$mail->MsgHTML($html);
// add alternate content 
$mail->AltBody($text);


// send the mail
if ($mail->Send()) {
   // mail sent correctly
} else {
   die("Uhoh, could not send to {$mail['email']}:" . $mail->ErrorInfo);
}
于 2010-08-30T13:39:35.057 に答える