<html>
<head>
<title>PHPMailer - SMTP (Gmail) authenrication</title>
</head>
<body>
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer(false); // the true param means it will throw exceptions on errors, which we need to catch
// - - - - - - - - - Email Configuration - - - - - - - - - //
// REQUIRED
//$user="arti@carinait.com";
$password="teamcarina2013";
$gmail_user = "arti@carinait.com"; // Gmail or Google Apps .. Send email from this email account
$gmail_pass = "$password"; // password
$name="";
$plant="";
$cancer="";
$target="";
$submiter="";
$ins="";
$email="";
$contact="";
$image="";
if(isset($_POST['new']))
{
$name=$_POST['name'];
$plant=$_POST['plant'];
$cancer=$_POST['cancer'];
$target=$_POST['target'];
$submiter=$_POST['submiter'];
$ins=$_POST['institut'];
$email=$_POST['email'];
$contact=$_POST['contact'];
$image=$_POST['image'];
$time=@date('H:m:s');
//$image_url=$_FILES['file']['name'];
$image=$time."_".$_FILES['file']['name'];
$url=$_FILES['file']['tmp_name'];
move_uploaded_file($url,'new_submit_image/'.$time."_".$_FILES['file']['name']);
}
//if(isset($_POST['submit']))
// REQUIRED
$to_email =$email; // Recipient of the online form message .. you will receive email here
$to_name = "New entry information";
// Recipient Name .. Own Company Name
// Redirect after sending email .. you can use a full url also with http://
$redirect = "http://www.carinait.in/demo1/index.php";
// - - - - - - - - - /Email Configuration - - - - - - - - - //
// - - - - - - - - - Input from the enquiry form - - - - - - - - - //
// - - - - - - - - - /Input from the enquiry form - - - - - - - - - //
// - - - - - - - - - Simple Message in Email - - - - - - - - - //
// Do Not Remove
$MailBody2 = '
';
// - - - - - - - - - /Simple Message in Email - - - - - - - - - //
if (isset($_POST['new'])) {
$MailBody = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mail</title>
</head>
<body>
<div style="font-family:Trebuchet MS,sans-serif; width:700px; margin:0px auto;">
<table width="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#9E8751" style="font-family:Trebuchet MS,sans-serif; padding-top:20px; padding-bottom:20px; ">
<tr>
<td>
<div style=" background-color:#F4F4E8; margin:0px auto;
width:90%; padding:20px; height:300px; font:16px calibri;">
<h3 style="text-align:center;
font: bold 25px georgia;
color:#525252;"> Information of New Entry </h3>
<table width="50%" style=" float:left; ">
<tr><td>Compound Name:</td></tr>
<tr><td>Plant:</td></tr>
<tr><td>Cancer Chemo preventive Activity:</td></tr>
<tr><td>Therapeutic Targets List:</td></tr>
<tr><td>Upload Structure :</td></tr>
<tr><td>Name of Submitter:</td></tr>
<tr><td>Institution of Submitter</td></tr>
<tr><td>Email Id of the Submitter</td></tr>
<tr><td>Contact Number of Submitter</td></tr>
</table>
<table width="50%" style=" float:left; ">
<tr><td>'.$plant.'</td></tr>
<tr><td>'.$cancer.'</td></tr>
<tr><td>'.$target.'</td></tr>
<tr><td>Upload Structure :</td></tr>
<tr><td>'.$submiter.'</td></tr>
<tr><td>'.$ins.'</td></tr>
<tr><td>'.$email.'</td></tr>
<tr><td>'.$contact.'</td></tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
';
// - - - - - - - - - /HTML Message in Email - - - - - - - - - //
}
//form body for student enquiry form
// - - - - - - - - - HTML Message in Email - - - - - - - - - //
if (isset($_POST['submitenquiry'])) {
// - - - - - - - - - /HTML Message in Email - - - - - - - - - //
}
//form body for student enquiry form
?>
<br>
<?
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = $gmail_user; // GMAIL username or Google Apps
$mail->Password = $gmail_pass; // GMAIL password
// - - - - - - - - - DO NOT EDIT THIS - - - - - - - - - //
// Sender Email
// $mail->SetFrom('', ''); // $mail->SetFrom('name@yourdomain.com', 'First Last');
$address = $email; // DO NOT Change this and the line below this line
$mail->SetFrom($address, $name); // $mail->SetFrom('name@yourdomain.com', 'First Last');
// - - - - - - - - - / END - - - - - - - - - //
// TO Recipient
$mail->AddAddress($to_email, $to_name); // $mail->AddReplyTo('name@yourdomain.com', 'First Last');
// $mail->AddReplyTo('name@yourdomain.com', 'First Last');
$address = $email;
$mail->AddReplyTo($address, $name);
// CC
$cc_cc;
// BCC
$bcc_bcc;
$mail->Subject = 'Message Through Website';
// $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
$mail->AltBody = $MailBody2; // optional - MsgHTML will create an alternate automatically
$body= $MailBody;
// $mail->MsgHTML(file_get_contents('contents.html'));
$mail->MsgHTML($body);
$mail->AddAttachment('images/phpmailer.gif'); // attachment
$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
// echo "Message sent!";
echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">";
echo "<META HTTP-EQUIV=\"Cache-Control\" CONTENT=\"no-cache\">";
echo "<META HTTP-EQUIV=\"Cache-Control\" CONTENT=\"no-store\">";
echo "<meta http-equiv='refresh' content='0; URL=$redirect'>";
}
/* catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}*/
//}
?>
</body>
</html>
i want to attach image with mail but getting error
Could not access file: images/phpmailer.gif Could not access file: images/phpmailer_mini.gif SMTP Error: Could not authenticate. Mailer Error: SMTP Error: Could not authenticate.
what i did wrong please help