仅通过php发送一次电子邮件
我现在正在学习PHP,想学习如何从diretory web向某人发送带有附件的电子邮件 我尝试使用这段代码,它成功了,但当我尝试再次向其他电子邮件地址发送电子邮件时,它没有再次发送,需要几小时(或几分钟,我不知道确切情况,只是我的猜测)才能再次工作。我不知道真正的问题是什么? 如果有人和我有同样的问题,请在这里分享。提前谢谢。对不起,我的英语不好 这是我的密码仅通过php发送一次电子邮件,php,email,Php,Email,我现在正在学习PHP,想学习如何从diretory web向某人发送带有附件的电子邮件 我尝试使用这段代码,它成功了,但当我尝试再次向其他电子邮件地址发送电子邮件时,它没有再次发送,需要几小时(或几分钟,我不知道确切情况,只是我的猜测)才能再次工作。我不知道真正的问题是什么? 如果有人和我有同样的问题,请在这里分享。提前谢谢。对不起,我的英语不好 这是我的密码 <?php session_start(); if (isset($_SESSION['xx'])
<?php
session_start();
if (isset($_SESSION['xx']) && $_SESSION['xx'] == session_id() ) {
//panggil file config.php untuk menghubung ke server
include('config.php');
//catch data from the form
$nmMhs = $_POST['name'];
$sexMhs = (isset($_POST['sex']))?$_POST['sex']:"";
$almMhs = $_POST['address'];
$tlpMhs = $_POST['telp'];
$date=$_POST['tgl']; $month=$_POST['bln']; $year=$_POST['thn'];
$tgllhrMhs = $date.'-'.$month.'-'.$year;
$emlMhs = $_POST['email'];
$prodiMhs = (isset($_POST['prodi']))?$_POST['prodi']:"";
$statMhs = (isset($_POST['stat']))?$_POST['stat']:"";
$klsMhs = (isset($_POST['kelas']))?$_POST['kelas']:"";
$orgMhs = $_POST['org'];
$sakitMhs = $_POST['sick'];
$almetMhs = (isset($_POST['almet']))?$_POST['almet']:"";
$kausMhs = (isset($_POST['kaos']))?$_POST['kaos']:"";
//send email
$email_to = $emlMhs; // The email you are sending to (example)
$email_from = "someone@gmail.com"; // The email you are sending from (example)
$email_subject = "subject of the messages"; // The Subject of the email
$email_txt = "hello everybody, this is a message"; // Message that the email has in it
//email attachment
$fileatt = "path/file"; // Path to the file (example)
$fileatt_type = "application/msword"; // File Type
$fileatt_name = "file.docx"; // Filename that will be used for the file as the attachment
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers="From: $email_from"; // Who the email is from (example)
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $email_txt;
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
//save data to database
if($prodiMhs == "S1 Manajemen"){
$query = mysql_query("insert into mhs_manajemen values(null, '$nmMhs', '$sexMhs', '$almMhs', '$tlpMhs', '$tgllhrMhs', '$emlMhs', '$prodiMhs', '$statMhs', '$klsMhs', '$orgMhs', '$sakitMhs', '$almetMhs', '$kausMhs' )") or die(mysql_error());
if ($query) {
mail($email_to,$email_subject,$email_message,$headers);
echo "<script type='text/javascript'>
window.alert('Data has been inputed')
window.location.href='isi_data.php';
</script>";
}
}
if($prodiMhs == "S1 Administrasi Niaga"){
$query = mysql_query("insert into mhs_administrasi values(null,'$nmMhs', '$sexMhs', '$almMhs', '$tlpMhs', '$tgllhrMhs', '$emlMhs', '$prodiMhs', '$statMhs', '$klsMhs', '$orgMhs', '$sakitMhs', '$almetMhs', '$kausMhs' )") or die(mysql_error());
if ($query) {
mail($email_to,$email_subject,$email_message,$headers);
echo "<script type='text/javascript'>
window.alert('Data has been inputed')
window.location.href='isi_data.php';
</script>";
}
}
} else {
session_destroy();
echo "<script type='text/javascript'>
window.alert('<b>Access denied! Please login first!<b>')
window.location.href='index.php';
</script>";
}
?>
如果使用else If
和else
而不仅仅是If
脚本将只执行两个代码块中的一个。因此,请尝试将else if直接放在if($prodiMhs==“S1 Manajemen”){
的结束方括号之后。基本上将if($prodiMhs==“S1 Administrasi Niaga”){
更改为else if($prodiMhs==“S1 Administrasi Niaga”){
我希望这对你有帮助。参考这个链接,希望这会有帮助:如果你能,你应该。他们不再被维护和学习。相反,要考虑使用PDO,Zzzzx。……