I am using the below code for a webform but getting the below error messages. Please help. Thanks.
Error 1
Code:
Warning: Cannot modify header information - headers already sent by (output started at class.phpmailer.php:1370) in processform.php on line 63
Error 2 - With this error message the attachment is not required but can upload max 4 files.
Code:
Could not access file: Array Could not access file: Array Could not access file: Array Could not access file: Array
PHP Code:
<?php
$errors = array();
if ('POST' === $_SERVER['REQUEST_METHOD'])
{
$name = sanitize($_POST['name']);
$email = sanitize($_POST['email']);
if (empty($name))
{
$errors['name'] = "Please provide name.";
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$errors['email'] = "Please provide a valid email address.";
}
// If there are no errors let's process the payment
if (count($errors) === 0)
{
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->From = $email;
$mail->AddAddress("myfriend@example.net");
$mail->Subject = "Test";
$mail->Body = "some message here.";
$mail->WordWrap = 50;
$mail->AddAttachment($_FILES['file']['tmp_name']);
$mail->AddAttachment($_FILES['file']['tmp_name']);
$mail->AddAttachment($_FILES['file']['tmp_name']);
$mail->AddAttachment($_FILES['file']['tmp_name']);
$mail->Send();
exit(header("Location: thankyou.php"));
} }
function sanitize($value)
{
return trim(strip_tags($value));
}
?>
Bookmarks