Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2017
1,091
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. <?php
  2. $to = 'nobody@example.com';
  3. $subject = 'the subject';
  4. $message = 'hello';
  5. $headers = 'From: webmaster@example.com' . "rn" .
  6. 'Reply-To: webmaster@example.com' . "rn" .
  7. 'X-Mailer: PHP/' . phpversion();
  8.  
  9. mail($to, $subject, $message, $headers);
  10. ?>
  11.  
  12. <?php
  13. require 'PHPMailerAutoload.php';
  14.  
  15. $mail = new PHPMailer;
  16.  
  17. $mail->isSMTP(); // Set mailer to use SMTP
  18. $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
  19. $mail->SMTPAuth = true; // Enable SMTP authentication
  20. $mail->Username = 'user@example.com'; // SMTP username
  21. $mail->Password = 'secret'; // SMTP password
  22. $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
  23.  
  24. $mail->From = 'from@example.com';
  25. $mail->FromName = 'Mailer';
  26. $mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
  27. $mail->addAddress('ellen@example.com'); // Name is optional
  28. $mail->addReplyTo('info@example.com', 'Information');
  29. $mail->addCC('cc@example.com');
  30. $mail->addBCC('bcc@example.com');
  31.  
  32. $mail->WordWrap = 50; // Set word wrap to 50 characters
  33. $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
  34. $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
  35. $mail->isHTML(true); // Set email format to HTML
  36.  
  37. $mail->Subject = 'Here is the subject';
  38. $mail->Body = 'This is the HTML message body <b>in bold!</b>';
  39. $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
  40.  
  41. if(!$mail->send()) {
  42. echo 'Message could not be sent.';
  43. echo 'Mailer Error: ' . $mail->ErrorInfo;
  44. } else {
  45. echo 'Message has been sent';
  46. }
  47.  
  48. // multiple recipients
  49. $to = 'aidan@example.com' . ', '; // note the comma
  50. $to .= 'wez@example.com';
  51.  
  52. // subject
  53. $subject = 'Birthday Reminders for August';
  54.  
  55. // message
  56. $message = '
  57. <html>
  58. <head>
  59. <title>Birthday Reminders for August</title>
  60. </head>
  61. <body>
  62. <p>Here are the birthdays upcoming in August!</p>
  63. <table>
  64. <tr>
  65. <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
  66. </tr>
  67. <tr>
  68. <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
  69. </tr>
  70. <tr>
  71. <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
  72. </tr>
  73. </table>
  74. </body>
  75. </html>
  76. ';
  77.  
  78. // To send HTML mail, the Content-type header must be set
  79. $headers = 'MIME-Version: 1.0' . "rn";
  80. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
  81.  
  82. // Additional headers
  83. $headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "rn";
  84. $headers .= 'From: Birthday Reminder <birthday@example.com>' . "rn";
  85. $headers .= 'Cc: birthdayarchive@example.com' . "rn";
  86. $headers .= 'Bcc: birthdaycheck@example.com' . "rn";
  87.  
  88. // Mail it
  89. mail($to, $subject, $message, $headers);
  90.  
  91. <?php
  92. include('Mail.php');
  93.  
  94. $recipients = 'joe@example.com';
  95.  
  96. $headers['From'] = 'richard@example.com';
  97. $headers['To'] = 'joe@example.com';
  98. $headers['Subject'] = 'Test message';
  99.  
  100. $body = 'Test message';
  101.  
  102. $smtpinfo["host"] = "smtp.server.com";
  103. $smtpinfo["port"] = "25";
  104. $smtpinfo["auth"] = true;
  105. $smtpinfo["username"] = "smtp_user";
  106. $smtpinfo["password"] = "smtp_password";
  107.  
  108.  
  109. // Create the mail object using the Mail::factory method
  110. $mail_object =& Mail::factory("smtp", $smtpinfo);
  111.  
  112. $mail_object->send($recipients, $headers, $body);
  113. ?>
  114.  
  115. <?php
  116. $to = 'SomeOtherEmailAddress@Domain.com';
  117. $subject = 'This is subject';
  118. $message = 'This is body of email';
  119. $from = "From: FirstName LastName <SomeEmailAddress@Domain.com>";
  120. mail($to,$subject,$message,$from);
  121.  
  122. require 'mail/swift_required.php';
  123.  
  124. $message = Swift_Message::newInstance()
  125. // The subject of your email
  126. ->setSubject('Jane Doe sends you a message')
  127. // The from address(es)
  128. ->setFrom(array('jane.doe@gmail.com' => 'Jane Doe'))
  129. // The to address(es)
  130. ->setTo(array('frank.stevens@gmail.com' => 'Frank Stevens'))
  131. // Here, you put the content of your email
  132. ->setBody('<h3>New message</h3><p>Here goes the rest of my message</p>', 'text/html');
  133.  
  134. if (Swift_Mailer::newInstance(Swift_MailTransport::newInstance())->send($message)) {
  135. echo json_encode([
  136. "status" => "OK",
  137. "message" => 'Your message has been sent!'
  138. ], JSON_PRETTY_PRINT);
  139. } else {
  140. echo json_encode([
  141. "status" => "error",
  142. "message" => 'Oops! Something went wrong!'
  143. ], JSON_PRETTY_PRINT);
  144. }
  145.  
  146. <?php
  147. $to = "somebody@example.com";
  148. $subject = "My subject";
  149. $txt = "Hello world!";
  150. $headers = "From: webmaster@example.com" . "rn" .
  151. "CC: somebodyelse@example.com";
  152.  
  153. mail($to,$subject,$txt,$headers);
  154. ?>
  155.  
  156. <?php
  157. // Multiple recipients
  158. $to = 'johny@example.com, sally@example.com'; // note the comma
  159.  
  160. // Subject
  161. $subject = 'Birthday Reminders for August';
  162.  
  163. // Message
  164. $message = '
  165. <html>
  166. <head>
  167. <title>Birthday Reminders for August</title>
  168. </head>
  169. <body>
  170. <p>Here are the birthdays upcoming in August!</p>
  171. <table>
  172. <tr>
  173. <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
  174. </tr>
  175. <tr>
  176. <td>Johny</td><td>10th</td><td>August</td><td>1970</td>
  177. </tr>
  178. <tr>
  179. <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
  180. </tr>
  181. </table>
  182. </body>
  183. </html>
  184. ';
  185.  
  186. // To send HTML mail, the Content-type header must be set
  187. $headers[] = 'MIME-Version: 1.0';
  188. $headers[] = 'Content-type: text/html; charset=iso-8859-1';
  189.  
  190. // Additional headers
  191. $headers[] = 'To: Mary <mary@example.com>, Kelly <kelly@example.com>';
  192. $headers[] = 'From: Birthday Reminder <birthday@example.com>';
  193. $headers[] = 'Cc: birthdayarchive@example.com';
  194. $headers[] = 'Bcc: birthdaycheck@example.com';
  195.  
  196. // Mail it
  197. mail($to, $subject, $message, implode("rn", $headers));
  198. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement