当有人填写表格时,我有PHP给我发了一封swiftmailer的电子邮件。
当我排除swiftmailer的代码并执行表格时,我会收到我的确认页面。
当我包含swiftmailer的代码时,邮件会被发送,但我没有收到我的确认页面。它只是在闪烁后停留在表单的页面上。
显示确认的代码和发送电子邮件的代码都在同一个文件中=>为registration.php。
任何帮助表示赞赏,亲切的问候。
PHP中的formprocessing代码
<!DOCTYPE html>
<html>
<head>
<title>Registratie voltooid</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../css/global.css">
</head>
<body>
<h1>Resultaat registratie</h1>
<h2>Persoonlijke info</h2>
<p><span class='green'>Succesvol</span> geüpload.</p><h2>Afbeeldingen</h2>
<?php
error_reporting(E_ALL);
$allowedTypes = array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PSD, IMAGETYPE_BMP, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM);
$input_file_name = "upload";
$uploads_dir = "../uploads";
$failed_uploads = [];
$succeeded_uploads = [];
foreach ($_FILES[$input_file_name]["error"] as $key => $error) {
$name = $_FILES[$input_file_name]["name"][$key];
if ($error == UPLOAD_ERR_OK) { //UPLOAD_ERR_OK equals errorcode 0 which stands for "no error"
$detectedType = exif_imagetype($_FILES[$input_file_name]['tmp_name'][$key]);
if (in_array($detectedType, $allowedTypes)) {
$tmp_name = $_FILES[$input_file_name]["tmp_name"][$key];
move_uploaded_file($tmp_name, $uploads_dir . "/" . $name);
$succeeded_uploads = $name;
} else {
$failed_uploads[] = $name;
}
} else {
if ($name != "") {
$failed_uploads[] = $name;
}
}
}
if (!empty($succeeded_uploads) && empty($failed_uploads)) {
echo "Alle afbeeldingen zijn <span class='green'>succesvol</span> geüpload</p>";
} else {
echo "<p><span class='green'>Succesvol</span> geüpload: <span class='green'>" . count($succeeded_uploads) . "</span>.<br /><span class='red'>Niet succesvol</span> geüpload: <span class='red'>" . count($failed_uploads) . "</span>.";
}
require_once '../lib_swiftmailer/swift_required.php';
//// Create the message
$message = Swift_Message::newInstance($subject)
->setFrom(array('johndoe#derp.com'))
->setTo(array('johndoe#derp.com'))
->setBody($body)
->addPart($body, 'text/html') //alternative body
;
// add uploaded files as attachments
if (!empty($uploads_dir)) {
$files = glob("$uploads_dir/*.{jpg,png,gif,tiff,psd,bmp}", GLOB_BRACE); // paths in []
foreach ($files as $AttachmentRelativePath) {
$attachment = Swift_Attachment::fromPath($AttachmentRelativePath);
$message->attach($attachment);
}
}
// Set up transport and send
$transport = Swift_SmtpTransport::newInstance('smtp.derpland.com', 587, 'tls')
->setUsername('xxxxx')
->setPassword('xxxxx')
;
$transport->setLocalDomain('[127.0.0.1]');
$mailer = Swift_Mailer::newInstance($transport);
$mailer->send($message);
// Remove files from uploaddir
$allUploadedFiles = glob($uploads_dir . "/*");
foreach ($allUploadedFiles as $file) {
unlink($file);
}
?>
</body>
</html>
#
表格
<!DOCTYPE html>
<html>
<head>
<title>PXL models</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="css/registration.css">
<style type="text/css">
</style>
</head>
<form action="php/registration.php" method="post" enctype="multipart/form-data">
<label for="First_nameLabel" class="label">Voornaam</label>
<input type="text" name="First_name" class="inputBox"/><br />
<label for="Last_nameLabel" class="label">Naam</label>
<input type="text" name="Last_name" class="inputBox"/><br />
<label for="E-mailLabel" class="label">E-mail</label>
<input type="text" name="E-mail" class="inputBox"/><br />
<label for="Telephone" class="label">Telefoon</label>
<input type="number" name="Telephone" class="inputBox"/><br />
<label for="Cellphone" class="label">Gsm</label>
<input type="number" name="Cellphone" class="inputBox"/><br />
<label for="gender" class="label">Geslacht</label>
<div class="surroundingDiv inputBox">
<input type="radio" name="Gender" checked="checked" value="Vrouw">Vrouw
<input type="radio" name="Gender" value="Man">Man
</div><br />
<div id="uploadLabel" class="label">Uploaden</div>
<div class="surroundingDiv">
<label id="uploadButton">
Upload foto's
<input type="file" multiple="multiple" name="upload[]" accept="image/*" />
</label>
</div>
<input type="submit" value="Bevestigen"><br /><br />
</form>
</html>