Reputation: 99
So I just made a contact form using phpmailer. I did everything right, as I know. Other people can somehow send emails. I managed to send emails without using the form (no submitting), just by loading the page.
but I want to send the data in the form to me, however it doesn't work with the submit...
here are my codes, the automailing by just loading the page is now in a comment.
<?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('[email protected]', $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('[email protected]', 'testme');
//set who is sending an email
$mail->setFrom('[email protected]', '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>
Upvotes: 0
Views: 65
Reputation: 1380
You are checking for $_POST['submit']
but your form does not contain it.
for it to work you have to add name="submit"
to your submit button:
<input class="button" style="width:350px;" name="submit" type="submit" value="bestellen">
Upvotes: 3