я на изучение PHP сейчас, и вы хотите, чтобы узнать, как отправить электронную почту от diretory сети, чтобы кто-то по электронной почте с приложением ,,отправить электронную почту с помощью PHP только один раз
я стараюсь с этим кодом, и она работала, но когда я попробуйте отправить электронное письмо еще раз на другой адрес электронной почты, он не отправил еще раз и понадобился несколько часов (или несколько минут, я точно не знал, просто думаю), чтобы снова работать. Я не знал, что такое настоящая проблема? Если у кого-то проблемы со мной, пожалуйста, поделитесь этим. заранее спасибо. и извините за мой плохой английский.
это мой код,
<?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 = "[email protected]"; // 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>";
}
?>
Ссылка на эту ссылку надеется, что это поможет: http://webcheatsheet.com/php/send_email_text_html_attachment.php –
Если вы можете, вы должны [прекратить использование 'mysql_ *' функций] (http://stackoverflow.com/questions/12859942/почему-я-не должны назначения-MySQL-функции-в-РНР). Они больше не поддерживаются и [официально устарели] (https://wiki.php.net/rfc/mysql_deprecation). Узнайте о [подготовленном] (http://en.wikipedia.org/wiki/Prepared_statement) [заявлениях] (http://php.net/manual/en/pdo.prepared-statements.php) и рассмотрите возможность использования PDO , [это действительно не сложно] (http://jayblanchard.net/demystifying_php_pdo.html). –