gpt4 book ai didi

php - 发送邮件到数据库

转载 作者:行者123 更新时间:2023-11-28 03:27:25 24 4
gpt4 key购买 nike

我想知道是否可以向数据库发送电子邮件?例如,如果你有一场比赛,当人们猜测你的问题或其中的一部分时,他们在提交表单中的输入应该保存在一个文件中的 DB 中,易于打开,供以后使用。这可能吗?

最佳答案

使用 php mail class() 中的示例

你可以有一个像这样获取所有邮件数据的类:

<?php
class mailProcessor {

public function _construct(){
$to = "";
$subject = "";
$message = "";
}

public function processEmail($to, $subject, $message){
//so validation here for the strings being inputed
//
if($to){
$this->to = $to;

}

//and so on

}

//if evertying is okay require the the mail class
require 'PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'jswan'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('josh@example.net', 'Josh Adams'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {

if($this->updateDatabase())
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}

public function updateDatabase(){
//get all local variables from the cosntructor
//
//update the databse with the new data
//
return true

//else should return false..
}
}


?>

因此需要进行更改,但这个想法足以使这项工作成功 :)

关于php - 发送邮件到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20330470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com