· 8 years ago · Sep 14, 2017, 12:06 AM
1class.phpmailer.php
2class.smtp.php
3index.php
4web.config
5
6<Center><h2>PHP Test Email Script</h2></center>
7<?php
8// display form if user has not clicked submit
9if (!isset($_POST["submit"])) {
10 ?>
11 <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>" target="_blank">
12<Table align = center>
13
14 <tr><td>From Email: <td><input type="text" name="uname"> i.e yourname@yourdomain.com</tr>
15 <tr><td>Email Password: <td><input type="password" name="pass"></tr>
16<tr><td>Host: <td><input type="text" name="host"> i.e Mail.YourDomain.com</tr>
17 <tr><td>To:<td> <input type="text" name="to"></tr>
18
19 <tr><td colspan =2 align = center><input type="submit" name="submit" value="Send Email"></tr>
20</table>
21 </form>
22
23 <?php
24}
25else { // the user has submitted the form
26
27include("class.phpmailer.php"); //you have to upload class files "class.phpmailer.php" and "class.smtp.php"
28
29$mail = new PHPMailer();
30
31$mail->IsSMTP();
32$mail->SMTPAuth = true;
33
34$mail->Host = $_POST["host"];
35
36$mail->Username = $_POST["uname"];
37$mail->Password = $_POST["pass"];
38
39$mail->From = $_POST["uname"];
40$mail->FromName = "demouser";
41
42$mail->AddAddress($_POST["to"],"test");
43$mail->Subject = "This is the subject";
44$mail->Body = "This is a sample message using SMTP authentication";
45$mail->WordWrap = 50;
46$mail->IsHTML(true);
47$str1= "gmail.com";
48$str2=strtolower($_POST["uname"]);
49If(strstr($str2,$str1))
50{
51$mail->SMTPSecure = 'tls';
52$mail->Port = 587;
53if(!$mail->Send()) {
54echo "Mailer Error: " . $mail->ErrorInfo;
55echo "<br><br> * Please double check the user name and password to confirm that both of them are correct. <br><br>";
56echo "* If you are the first time to use gmail smtp to send email, please refer to this link :http://www.smarterasp.net/support/kb/a1546/send-email-from-gmail-with-smtp-authentication-but-got-5_5_1-authentication-required-error.aspx?KBSearchID=137388";
57}
58else {
59echo "Message has been sent";
60}
61}
62else{
63 $mail->Port = 25;
64 if(!$mail->Send()) {
65echo "Mailer Error: " . $mail->ErrorInfo;
66echo "<br><BR>* Please double check the user name and password to confirm that both of them are correct. <br>";
67}
68else {
69echo "Message has been sent";
70}
71}
72}
73?>