Advertisement
Guest User

Untitled

a guest
Jan 25th, 2016
1,257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 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. <?php
  123. $to = "somebody@example.com";
  124. $subject = "My subject";
  125. $txt = "Hello world!";
  126. $headers = "From: webmaster@example.com" . "rn" .
  127. "CC: somebodyelse@example.com";
  128.  
  129. mail($to,$subject,$txt,$headers);
  130. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement