I found this code online, and it works like a charm only for one thing... I was also trying to add a phone number but I keep getting an error every time... I would imagine that I would just add it to the body but every time i try to, it fails. im not really sure what im doing wrong. Im fairly new to PHP so if someone could explain to me why this is happening, that would be greatly appreciated. The content is stored into a folder, but it doesnt seem that folder is refreshed once the email is sent... :\
<?php
$msg = "";
if (isset($_POST['submit'])) {
require 'phpmailer/PHPMailerAutoload.php';
function sendemail($to, $from, $fromName, $body, $attachment = "") {
$mail = new PHPMailer();
$mail->setFrom($from, $fromName);
$mail->addAddress($to);
$mail->addAttachment($attachment);
$mail->Subject = 'Contact Form - Email';
$mail->Body = $body;
$mail->isHTML(false);
return $mail->send();
}
$name = $_POST['username'];
$email = $_POST['email'];
$body = $_POST['body'];
$file = "attachment/" . basename($_FILES['attachment']['name']);
if (move_uploaded_file($_FILES['attachment']['tmp_name'], $file)) {
if (sendemail('email@mail.net', $email, $name, $body, $file)) {
$msg = 'Email sent!';
} else
$msg = 'Email failed!';
} else
$msg = "Please check your attachment!";
}
?>
<html>
<head>
<title>Contact</title>
</head>
<style type="text/css">
input, textarea {
width:250px;
height: 27px;
margin-bottom: 10px;
}
textarea {
height: 200px;
width: 100%;
resize: vertical;
}
body {
text-align: center;
margin-top: 250px;
}
</style>
<body>
<img src="images/logo.png"><br><br>
<form method="post" action="index.php" enctype="multipart/form-data">
<input type="text" name="username" placeholder="Name..." required><br>
<input type="email" name="email" placeholder="Email..." required><br>
<textarea name="body" placeholder="Message..." required></textarea><br>
<input type="file" name="attachment" required><br>
<input type="submit" name="submit" value="Send Email">
</form>
<br><br>
<?php echo $msg; ?>
</body>