我写了一个脚本,假设在新订阅时发送和发送电子邮件,但邮件功能不发送。它从数据库中获取电子邮件并将其添加到我发现不发送的from字段中,但如果我只输入一封电子邮件就可以了。
邮件脚本:
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$a = curPageURL();
$b = explode('/',$a);
$value = $b['3'];
// Get date from MySQL Server
$currentdate = mysql_query('select CURDATE()');
$curdate = mysql_result($currentdate,0);
$dayone = 1;
// Insert the new user to the database since everything is fine
$stmt = $mysqli->prepare("INSERT INTO optionusers (userid, name, email, join_date, day_one)
VALUES
(?, ?, ?, ?, ?)");
$stmt->bind_param('ssssi', $value, $name, $email, $curdate, $dayone);
$stmt->execute();
$inserted_id = $mysqli->insert_id;
$stmt->close();
global $mysqli;
$sql = "SELECT * FROM optionusers WHERE userid = '$value' AND join_date ='$curdate' AND day_one ='$dayone'";
$optinuseremails = $mysqli->query($sql);
while($row = $optinuseremails->fetch_object()){
$optinemails .= $row->email. ", ";
echo $optinemails;
//Select email address from userdata table
$stmt = $mysqli->query("SELECT * FROM userdata WHERE userid = '$value'");
$reffer = $stmt->fetch_object();
$stmt->close();
$refferinfo = $reffer->email_address;
echo $refferinfo;
//Select email template
$stmt = $mysqli->query("SELECT * FROM email_templates WHERE serial = '1'");
$result = $stmt->fetch_object();
$stmt->close();
$template1 = $result->serial;
$template_subject = $result->subject;
$template_text = $result->message;
eval("\$body=\"$template_text\";");
$header = "Content-type:text/html \r\n";
$header .= "From: ".$refferinfo." \r\n";
if(!mail($optinemails,$template_subject,$body,$header)){
echo "could not send mail";
}else{
mail($optinemails,$template_subject,$body,$header);
}
$from = $refferinfo; // sender
$subject = "It is 3 days";
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = "It is now 3 days the script works";
// send mail
mail("carltondavis19@gmail.com",$subject,$message,"From: $from\n");
}
//Update day value if user already got emailed
$stmt = $mysqli->prepare("UPDATE optionusers SET day_one = 1 WHERE userid = '$value' AND day_one = '0'");
$stmt->execute();
$stmt->close();