所以我只是使用phpmailer制作了联系表格。 据我所知,我做对了所有事情。其他人可以通过某种方式发送电子邮件。我仅通过加载页面就可以不使用表单(不提交)发送电子邮件。
但是我想将表单中的数据发送给我,但是不适用于提交...
这是我的代码,通过仅加载页面进行的自动邮寄现在在注释中。
<?php
$msg = "";
if (isset($_POST['submit'])) {
require 'phpmailer/PHPMailerAutoload.php';
function sendemail($to, $from, $fromName, $body, $attachment) {
$mail = new PHPMailer();
$mail->addAddress($to);
$mail->setFrom($from, $fromName);
$mail->Subject = "Test email!";
$mail->isHTML(false);
$mail->Body = $body;
$mail->addAttachment($attachment);
return $mail->send();
}
$name = $_POST['vorname'] + ' ' + $_POST['nachname'];
$email = $_POST['email'];
$body = $_POST['address'] + ', ' + $_POST['plz'] + ', ' + $_POST['ort'];
$file = "attachment/" . basename($_FILES['attachment']['name']);
if (move_uploaded_file($_FILES['attachment']['tmp_name'], $file)) {
if (sendemail('tareq@thejami.com', $email, $name, $body, $file))
$msg = "email sent";
else
$msg = "failed";
} else
$msg= "fail";
}
/*
//we need to create an instance of PHPMailer
$mail = new PHPMailer();
//set where we are sending email
$mail->addAddress('tareq@thejami.com', 'testme');
//set who is sending an email
$mail->setFrom('myappkl@gmail.com', 'Admin at CPI');
//set subject
$mail->Subject = "Test email!";
//type of email
$mail->isHTML(true);
//write email
$mail->Body = "<p>this is our email body</p><br><br><a href='http://google.com'>Google</a>";
//include attachment
$mail->addAttachment('fbcover.png', 'Facebook cover.png');
//send an email
if (!$mail->send())
echo "Something wrong happened!";
else
echo "Mail sent";
*/
?>
<html lang="de">
<body>
<form method="post" action="index.php" enctype="multipart/form-data" class="formular">
<h2>Bestellformular</h2>
Name:<span class="required">*</span><br>
<input class="texte" style="width:170px;" required type="text" name="vorname" placeholder="Vorname"><input class="texte" style="width:170px;" required type="text" name="nachname" placeholder="Nachname"><br>
Email:<span class="required">*</span><br>
<input class="texte" required style="width:350px;" type="email" name="email" placeholder="Email"><br>
Adresse:<span class="required">*</span><br>
<input class="texte" required style="width:350px;" type="text" name="address" placeholder="Straße, HausNr."><br>
<input class="texte" required style="width:170px;" type="number" name="plz" placeholder="PLZ"><input class="texte" required style="width:170px;" type="text" name="ort" placeholder="Ort"><br>
Handy:<br>
<input class="texte" style="width:350px;" type="number" name="nummer" placeholder="Handynummer <optional>"><br>
Bild aussuchen:<span class="required">*</span><br>
<input required class="texte" style="width:350px;" type="file" name="attachment"><br>
<input class="button" style="width:350px;" type="submit" value="bestellen"><br>
</form><br>
<?php echo $msg; ?>
</body>
</html>
答案 0 :(得分:3)
您正在检查$_POST['submit']
,但您的表单不包含它。
要使其正常工作,您必须将name="submit"
添加到提交按钮:
<input class="button" style="width:350px;" name="submit" type="submit" value="bestellen">