i'm using PHPMailer, JavaScript and PHP, through my code i send the email to specific user, next step is attach a file with the email.
But i have two questions about that:
- first one is related with the following code:
HTML part:
<input type="file" name="myFile" id="myFile" required/>
I'm using this one to attach the file, part of the email
JavaScript part, my function to send email (so far i can send an email with test data)
function SendMail(){
var cod="1234"; var subject="hello my friend";
$.get("SendMail.php?cod="+cod+"&subject="+subject+""); // (1)
}
In (1) how can i send the input file attached to my php file?
Like,
$.get("SendMail.php?cod="+cod+"&subject="+subject+"&mail="FileRelatedWithInputID);
- When i got successfully the file in PHP, how have i to format it to attach it to the email using PHPMailer?
That's it, my two questions about this issue, i appreciate your answers and suggestions.
Thank you for your time and attention.
Edited:
My PHP file:
require '../PHPMailer_5.2.4/PHPMailerAutoload.php';
$server = "localhost";
$user = "root";
$pass = "pass";
$bd = "BD";
$strHTML1=$_GET["cod"];
$strHTML2=$_GET["subject"];
// HOW DO I _GET THE FILE FROM JS AND FORMAT FILE PROPERLY TO THE MAIL?
$strHTML3= $strHTML1.$strHTML2;
$mail="mail@gmail.com";
session_start();
$conexion = mysqli_connect($server, $user, $pass,$bd)
or die("ERROR");
$mail = new PHPMailer();
$mail->isSMTP();
$mail->CharSet = "UTF-8";
$mail->SMTPDebug = 2;
$mail->Mailer = "smtp";
$mail->WordWrap = 50;
$mail->PluginDir = "../tickets/PHPMailer_5.2.4/";
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = "mail@site.com.en";
$mail->Password = "12345";
$mail->SMTPSecure = 'ssl';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From:Home\r\n";
$mail->AddAddress($mail, "test");
$mail->isHTML(true);
$mail->Subject = $strHTML2;
$mail->Body =$strHTML3;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo.' ';
exit;
}
$close = mysqli_close($conexion)
or die("ERROR");