Php Mailer Attatchment Error

Почта отправляется без вложения, но когда я добавляю вложение, почта не отправляется, вот код

использовать PHPMailer \ PHPMailer \ PHPMailer;
использовать PHPMailer \ PHPMailer \ Exception;

// Загрузка автозагрузчика композитора
требуют ‘vendor / autoload.php’;

// Database connection
require __DIR__ . '/include/database.php';
$db = DB();

//this is our upload folder
$upload_path = 'testimage/';

//response array
$response = array();

if($_SERVER['REQUEST_METHOD']=='POST'){

if(isset($_POST['Name']) and isset($_FILES['Photo']['name']) and isset($_POST['Email']) and isset($_POST['Location']) and isset($_POST['Facility'])){

date_default_timezone_set('Asia/Calcutta');
$t_date = date('Y-m-d H:i:s');

$now = DateTime::createFromFormat('U.u', microtime(true));
$new_name = $now->format('YmdHisu');

$name = $_POST['Name'];
$email = $_POST['Email'];
$facility= $_POST['Facility'];
$location = $_POST['Location'];
$fileinfo = pathinfo($_FILES['Photo']['name']);
$extension = $fileinfo['extension'];
$file_url = $upload_path . $new_name . '.' . $extension;
$file_path = $upload_path . $new_name . '.'. $extension;

$full_path = "http://website.com/foldername/$file_path";

try{
move_uploaded_file($_FILES['Photo']['tmp_name'],$file_path);

$db = DB();
$query = $db->prepare("INSERT INTO test_details(Name , Photo , Email, Facility, Location , Timestamp) VALUES (:name , :photo, :email , :facility, :location , :time)");
$query->bindParam("name", $name, PDO::PARAM_STR);
$query->bindParam("photo", $file_path, PDO::PARAM_STR);
$query->bindParam("email", $email, PDO::PARAM_STR);
$query->bindParam("facility", $facility, PDO::PARAM_STR);
$query->bindParam("location", $location, PDO::PARAM_STR);
$query->bindParam("time", $t_date, PDO::PARAM_STR);

if ( $query->execute())
{
$mail = new PHPMailer(true);                              // Passing `true` enables exceptions
try {
$mail->SMTPDebug = 2;                                 // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'mail.host.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'xxxxxxx';                 // SMTP username
$mail->Password = 'xxxx';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to
$mail->setFrom('xxxxxxx', 'xxxxxxxx');
$mail->addAddress($email);               // Name is optional
$mail->AddAttachment("$full_path");if($mail->send()){
echo 'Data Submit Successfully';
}
}
catch (Exception $e) {
echo 'Message could not be sent.';

}
}

}catch(Exception $e){
$response['error']=true;
$response['message']=$e->getMessage();
}
}else{
echo "Error Occured";
}
}

Почта не отправляется с вложением, когда я отправлю письмо без вложения, оно будет отправлено, но не отправлено с вложением
ошибка шоу не может получить доступ к файлу, чем имя файла

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector