私は現在、お見積りフォームを作成中です。フォームを送信した後、提出されたレコードをコピーとしてクライアントに送り返すように設定された電子メールがありました。しかし、私はトランザクション電子メールのためにMandrillを使用していたので、もはや無料ではありません。有料のサービスを使用したくないので、PHPMailerを使用して同じメールを送信しようとしています。私はそれが電子メールを送信するためにPHPを呼び出すことを理解するのが難しいと思っている。どんな助け?私はオプションのために開いています。フォーム提出後にメールを送信したいだけです。データベースにデータを投稿した後にPHPメールを送信する方法
email.js
function finalize_things(data, order_id){
//posting data to the server side page
$.post(window.location.origin+'/post/', data,function(response){
if(response == 'success'){
console.log(response);
send_email(order_id, data.email, data.firstname, data.project_details, data.file_names);
} else {
console.log(response);
alert('order not placed.');}
});
}
function send_email(order_id, email, firstname, project_details, file_names){
var html_message = "message here"
data = {
"key": "xxxxxxxxx",
"message": {
"html": html_message,
"text": "",
"subject": "Your subject",
"from_email": "[email protected]",
"from_name": "Company name",
"to": [{
"email": email,
"name": firstname
}
]},
"async": false
};
$.ajax({url: 'https://mandrillapp.com/api/1.0/messages/send.json',
type: 'POST',
data: data,
success: function(resp){
console.log(resp); }
});
phpmailerのコード:
だから、 include_once '/../../PHPMailer/cms_db.php';
require_once '/../../PHPMailer/PHPMailerAutoload.php';
require_once '/../../PHPMailer/config.php';
if (isset($_POST["email"]) && !empty($_POST["email"])) {
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Host = $smtp_server; // Specify main and backup SMTP servers
$mail->Username = $username; // SMTP username
$mail->Password = $password; // SMTP password
$mail->SMTPSecure = "tls"; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom("[email protected]", "Company Name");
$mail->addAddress($email, $firstname); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$bodyContent = "test message";
$mail->Subject = "Your Quote ID";
$mail->Body = $bodyContent;
$mail->AltBody = $bodyContent;
if(!$mail->send()) {
echo "Message could not be sent.";
$error = '<div class="alert alert-danger"><strong>Mailer Error: '. $mail->ErrorInfo.'</strong></div>';
} else {
$error = '<div class="alert alert-success"><strong>Message has been sent</strong></div>';
}
}
あるどの部分あなたは理解していない?より具体的になりますか? – Confiqure
JavaScriptでPHP電子メールコードを使用するにはどうすればよいですか? console.logの後と同様に、電子メールを送信し、phpmailerでデータを投稿した後で電子メールを送信する方法を教えてください。 $ .AJAX ..とはどうすればいいですか? –