Guest User

Untitled

a guest
Aug 7th, 2018
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. sending email recipient using PHP
  2. <?php
  3. require_once('auth.php');
  4.  
  5.  
  6. <html>
  7. <head>
  8. <title>PHPMailer - SMTP basic test with authentication</title>
  9. </head>
  10. <body>
  11.  
  12.  
  13. include("Connections/connection.php");
  14. //error_reporting(E_ALL);
  15. error_reporting(E_STRICT);
  16.  
  17. date_default_timezone_set('Europe/Dublin');
  18.  
  19. require_once('php_mailer/class.phpmailer.php');
  20. //include("class.smtp.php"); // optional, gets called from withinclass.phpmailer.php if not already loaded
  21.  
  22. $mail = new PHPMailer();
  23.  
  24.  
  25. //$body = file_get_contents('contents.php');
  26. //$body = eregi_replace("[]",'',$body);
  27.  
  28. $sender_name = $_SESSION['sender_name'];
  29. $sender_email = $_SESSION['sender_email'];
  30. $sender_password = $_SESSION['sender_password'];
  31.  
  32.  
  33. $id_user = $_POST["id_user"];
  34.  
  35. foreach ($id_tariff as $idt)
  36. {
  37. $query = sprintf("SELECT From_Date, To_Date, first, last, city, country, Email_1, Email_2, account_name FROM user_info where id_user = $id_user");
  38. $result = mysql_query($query) or die(mysql_error());
  39.  
  40.  
  41. $body = "
  42. <table width='100%' border='1' cellspacing='0' cellpadding='3' bordercolor='#ffcccc'>
  43. <tr>
  44. <th bgcolor='#cc3333'>From</th>
  45. <th bgcolor='#cc3333'>To</th>
  46. <th bgcolor='#cc3333'>First Name</th>
  47. <th bgcolor='#cc3333'>Last Name</th>
  48. <th bgcolor='#cc3333'>City</th>
  49.  
  50. <th bgcolor='#cc3333'>country</th>
  51.  
  52. </tr>
  53.  
  54.  
  55. ";
  56.  
  57.  
  58. while($row = mysql_fetch_array($result)){
  59. $body .="<tr>";
  60. $body .="<td>".$row['From_Date']."</td>";
  61. $body .="<td bgcolor='#FFE8E8'>".$row['To_Date']."</td>";
  62. $body .="<td>".$row['first']."</td>";
  63. $body .="<td bgcolor='#FFE8E8'>".$row['last']."</td>";
  64. $body .="<td>".$row['city']."</td>";
  65. $body .="<td bgcolor='#FFE8E8'>".$row['country']."</td>";
  66. $body .="</tr>";
  67. $to1 = $row['Email_1'];
  68. $to2 = $row['Email_2'];
  69. $account_name = $row['account_name'];
  70. }
  71. $body .="</table>";
  72.  
  73.  
  74. $mail->IsSMTP(); // telling the class to use SMTP
  75. $mail->Host = "smtp.gmail.com"; // SMTP server
  76. $mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
  77. // 1 = errors and messages
  78. // 2 = messages only
  79. $mail->SMTPAuth = true; // enable SMTP authentication
  80. $mail->SMTPSecure = "ssl";
  81. $mail->Host = "smtp.gmail.com"; // sets the SMTP server
  82. $mail->Port = 465; // set the SMTP port for the GMAIL server
  83. $mail->Username = "$sender_email"; // SMTP account username
  84. $mail->Password = "$sender_password"; // SMTP account password
  85.  
  86.  
  87. $mail->SetFrom($sender_email,$sender_name);
  88.  
  89. $mail->AddReplyTo("$sender_email","$sender_name");
  90.  
  91.  
  92. $mail->Subject = "Hello Dear $account_name";
  93.  
  94.  
  95. $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
  96.  
  97. $mail->MsgHTML($body);
  98.  
  99.  
  100.  
  101. $mail->AddAddress($to1,$account_name);
  102.  
  103. $mail->AddAddress($to2,$account_name);
  104.  
  105.  
  106.  
  107.  
  108. if(!$mail->Send()) {
  109. echo "Mailer Error: " . $mail->ErrorInfo;
  110. } else {
  111. echo "YOUR E-MAIL HAS SENT";
  112.  
  113. }
  114.  
  115.  
  116. }
  117. ?>
  118.  
  119. </body>
  120. </html>
Add Comment
Please, Sign In to add comment