Как отправить почту на PHP с вложениями
Я использую PHP для отправки почты с прикреплением, используя приведенный ниже код. я работаю нормально, но не получал никакой почты в EMail ID
Что я уже пробовал:
<?php if(isset($_FILES['image'])){ $errors= array(); $file_name = $_FILES['image']['name']; $file_size = $_FILES['image']['size']; $file_tmp = $_FILES['image']['tmp_name']; $file_type = $_FILES['image']['type']; // $file_ext=strtolower(end(explode('.',$_FILES['image']['name']))); $array = explode('.', $file_name); $file_ext = end( $array); $expensions= array("jpeg","jpg","png","pdf"); if(in_array($file_ext,$expensions)=== false){ $errors[]="extension not allowed, please choose a PDF, JPEG or PNG file."; } if($file_size > 2097152) { $errors[]='File size must be excately 2 MB'; } if(empty($errors)==true) { //move_uploaded_file($file_tmp,"uploads/".$file_name); //The folder where you would like your file to be saved echo "Success"; }else{ print_r($errors); } } // PHPMailer script below $email = $_REQUEST['email'] ; $name = $_REQUEST['name'] ; $phone = $_REQUEST['phone'] ; $message = $_REQUEST['message'] ; if (!class_exists("phpmailer")) { require_once('PHPMailer_5.2.0/class.phpmailer.php'); } $mail = new PHPMailer(true); $mail->IsSMTP(); $mail->Host = "smtp.gmail.com"; $mail->SMTPAuth = true; $mail->Username = "MY EMail ID"; // SMTP username $mail->Password = "******"; // SMTP password //$mail->addAttachment("uploads/".$file_name); $mail->AddAttachment($file_tmp, $file_name); $mail->From = $email; $mail->SMTPSecure = 'ssl'; $mail->Port = 25; //SMTP port $mail->addAddress("xyz@gmail.com", "Name"); $mail->Subject = "You have an email from a website visitor!"; $mail->Body =" Name: $name<br> Email: $email<br> Telephone: $phone<br><br><br> Comments: $message"; $mail->AltBody = $message; if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } echo "<script>alert('Message has been sent')</script>"; ?>