Advertisement
HenryGlazt

mailer

Nov 22nd, 2017
2,965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.25 KB | None | 0 0
  1. <?php
  2.     $name = $_POST['name'];
  3.     $email = $_POST['email'];
  4.     $message = $_POST['message'];
  5.     $from = 'From: yoursite.com';
  6.     $to = 'contact@yoursite.com';
  7.     $subject = 'Customer Inquiry';
  8.     $body = "From: $namen E-Mail: $emailn Message:n $message";
  9.  
  10.     if ($_POST['submit']) {
  11.         if (mail ($to, $subject, $body, $from)) {
  12.             echo '<p>Your message has been sent!</p>';
  13.         } else {
  14.             echo '<p>Something went wrong, go back and try again!</p>';
  15.         }
  16.     }
  17. ?>
  18.    
  19. error_reporting(-1);
  20. ini_set('display_errors', 'On');
  21. set_error_handler("var_dump");
  22.    
  23. $headers = array("From: from@example.com",
  24.     "Reply-To: replyto@example.com",
  25.     "X-Mailer: PHP/" . PHP_VERSION
  26. );
  27. $headers = implode("rn", $headers);
  28. mail($to, $subject, $message, $headers);
  29.    
  30. $headers = array("From from@example.com", // missing colon
  31.     "Reply To: replyto@example.com",      // missing hyphen
  32.     "X-Mailer: "PHP"/" . PHP_VERSION      // bad quotes
  33. );
  34.    
  35. $to = 'user@example.com';
  36. // other variables ....
  37. mail($recipient, $subject, $message, $headers); // $recipient should be $to
  38.    
  39. mail('user@example.com', $subject, $message, $headers);
  40.    
  41. ini_set("mail.log", "/tmp/mail.log");
  42. ini_set("mail.add_x_header", TRUE);
  43.    
  44. $header = "From: noreply@example.comrn";
  45. $header.= "MIME-Version: 1.0rn";
  46. $header.= "Content-Type: text/html; charset=ISO-8859-1rn";
  47. $header.= "X-Priority: 1rn";
  48.  
  49. $status = mail($to, $subject, $message, $header);
  50.  
  51. if($status)
  52. {
  53.     echo '<p>Your mail has been sent!</p>';
  54. } else {
  55.     echo '<p>Something went wrong, Please try again!</p>';
  56. }
  57.    
  58. function send_mail($email, $recipient_name, $message='')
  59. {
  60.     require("phpmailer/class.phpmailer.php");
  61.  
  62.     $mail = new PHPMailer();
  63.  
  64.     $mail->CharSet="utf-8";
  65.     $mail->IsSMTP();                                      // set mailer to use SMTP
  66.     $mail->Host = "mail.example.com";  // specify main and backup server
  67.     $mail->SMTPAuth = true;     // turn on SMTP authentication
  68.     $mail->Username = "myusername";  // SMTP username
  69.     $mail->Password = "p@ssw0rd"; // SMTP password
  70.  
  71.     $mail->From = "me@walalang.com";
  72.     $mail->FromName = "System-Ad";
  73.     $mail->AddAddress($email, $recipient_name);
  74.  
  75.     $mail->WordWrap = 50;                                 // set word wrap to 50 characters
  76.     $mail->IsHTML(true);                                  // set email format to HTML (true) or plain text (false)
  77.  
  78.     $mail->Subject = "This is a Sampleenter code here Email";
  79.     $mail->Body    = $message;
  80.     $mail->AltBody = "This is the body in plain text for non-HTML mail clients";    
  81.     $mail->AddEmbeddedImage('images/logo.png', 'logo', 'logo.png');
  82.     $mail->addAttachment('files/file.xlsx');
  83.  
  84.     if(!$mail->Send())
  85.     {
  86.        echo "Message could not be sent. <p>";
  87.        echo "Mailer Error: " . $mail->ErrorInfo;
  88.        exit;
  89.     }
  90.  
  91.     echo "Message has been sent";
  92. }
  93.    
  94. $headers  = "MIME-Version: 1.0" . "rn";
  95. $headers .= "Content-type: text/html; charset=iso-8859-1" . "rn";
  96. $headers .= "From: ". $from. "rn";
  97. $headers .= "Reply-To: ". $from. "rn";
  98. $headers .= "X-Mailer: PHP/" . phpversion();
  99. $headers .= "X-Priority: 1" . "rn";
  100.    
  101. mail('email@gmail.com', $subject, $message, $headers)
  102.    
  103. <?php
  104. $name = $_POST['name'];
  105. $email = $_POST['email'];
  106. $message = $_POST['message'];
  107. $from = 'From: yoursite.com';
  108. $to = 'contact@yoursite.com';
  109. $subject = 'Customer Inquiry';
  110. $body = "From: $namen E-Mail: $emailn Message:n $message";
  111.  
  112. $headers .= "MIME-Version: 1.0rn";
  113. $headers .= "Content-type: text/htmlrn";
  114. $headers .= 'From: from@example.com' . "rn" .
  115. 'Reply-To: reply@example.com' . "rn" .
  116. 'X-Mailer: PHP/' . phpversion();
  117.  
  118. mail($to, $subject, $message, $headers);
  119.    
  120. $config = Array(
  121.         'protocol' => 'smtp',
  122.         'smtp_host' => 'mail.domain.com', //your smtp host
  123.         'smtp_port' => 26, //default port smtp
  124.         'smtp_user' => 'name@domain.com',
  125.         'smtp_pass' => 'password',
  126.         'mailtype' => 'html',
  127.         'charset' => 'iso-8859-1',
  128.         'wordwrap' => TRUE
  129. );
  130. $message = 'Your msg';
  131. $this->load->library('email', $config);
  132. $this->email->from('name@domain.com', 'Title');
  133. $this->email->to('emaildestination@domain.com');
  134. $this->email->subject('Header');
  135. $this->email->message($message);
  136.  
  137. if($this->email->send())
  138. {
  139.    //conditional true
  140. }
  141.    
  142. $mail->SMTPDebug = 2;
  143.    
  144. <?php
  145.     $SmtpServer="smtp.*.*";
  146.     $SmtpPort="2525"; //default
  147.     $SmtpUser="***";
  148.     $SmtpPass="***";
  149. ?>
  150.    
  151. <?php
  152. class SMTPClient
  153. {
  154.  
  155.     function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
  156.     {
  157.  
  158.         $this->SmtpServer = $SmtpServer;
  159.         $this->SmtpUser = base64_encode ($SmtpUser);
  160.         $this->SmtpPass = base64_encode ($SmtpPass);
  161.         $this->from = $from;
  162.         $this->to = $to;
  163.         $this->subject = $subject;
  164.         $this->body = $body;
  165.  
  166.         if ($SmtpPort == "")
  167.         {
  168.             $this->PortSMTP = 25;
  169.         }
  170.         else
  171.         {
  172.             $this->PortSMTP = $SmtpPort;
  173.         }
  174.     }
  175.  
  176.     function SendMail ()
  177.     {
  178.         $newLine = "rn";
  179.         $headers = "MIME-Version: 1.0" . $newLine;  
  180.         $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;  
  181.  
  182.         if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
  183.         {
  184.             fputs ($SMTPIN, "EHLO ".$HTTP_HOST."rn");
  185.             $talk["hello"] = fgets ( $SMTPIN, 1024 );
  186.             fputs($SMTPIN, "auth loginrn");
  187.             $talk["res"]=fgets($SMTPIN,1024);
  188.             fputs($SMTPIN, $this->SmtpUser."rn");
  189.             $talk["user"]=fgets($SMTPIN,1024);
  190.             fputs($SMTPIN, $this->SmtpPass."rn");
  191.             $talk["pass"]=fgets($SMTPIN,256);
  192.             fputs ($SMTPIN, "MAIL FROM: <".$this->from.">rn");
  193.             $talk["From"] = fgets ( $SMTPIN, 1024 );
  194.             fputs ($SMTPIN, "RCPT TO: <".$this->to.">rn");
  195.             $talk["To"] = fgets ($SMTPIN, 1024);
  196.             fputs($SMTPIN, "DATArn");
  197.             $talk["data"]=fgets( $SMTPIN,1024 );
  198.             fputs($SMTPIN, "To: <".$this->to.">rnFrom: <".$this->from.">rn".$headers."nnSubject:".$this->subject."rnrnrn".$this->body."rn.rn");
  199.             $talk["send"]=fgets($SMTPIN,256);
  200.             //CLOSE CONNECTION AND EXIT ...
  201.             fputs ($SMTPIN, "QUITrn");
  202.             fclose($SMTPIN);
  203.             //
  204.         }
  205.         return $talk;
  206.     }
  207. }
  208. ?>
  209.    
  210. <?php
  211. include('SMTPconfig.php');
  212. include('SMTPmail.php');
  213. if($_SERVER["REQUEST_METHOD"] == "POST")
  214. {
  215.     $to = "";
  216.     $from = $_POST['email'];
  217.     $subject = "Enquiry";
  218.     $body = $_POST['name'].'</br>'.$_POST['companyName'].'</br>'.$_POST['tel'].'</br>'.'<hr />'.$_POST['message'];
  219.     $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
  220.     $SMTPChat = $SMTPMail->SendMail();
  221. }
  222. ?>
  223.    
  224. <?php
  225.     $name = $_POST['name'];
  226.     $email = $_POST['email'];
  227.     $message = $_POST['message'];
  228.     $from = 'From: yoursite.com';
  229.     $to = 'contact@yoursite.com';
  230.     $subject = 'Customer Inquiry';
  231.     $body = "From:" .$name."rn E-Mail:" .$email."rn Message:rn" .$message;
  232.  
  233. if (isset($_POST['submit']))
  234. {
  235.     if (mail ($to, $subject, $body, $from))
  236.     {
  237.         echo '<p>Your message has been sent!</p>';
  238.     }
  239.     else
  240.     {
  241.         echo '<p>Something went wrong, go back and try again!</p>';
  242.     }
  243. }
  244.  
  245. ?>
  246.    
  247. $name = $_POST['name'];
  248. $email = $_POST['email'];
  249. $reciver = '/* Reciver Email address */';
  250. if (filter_var($reciver, FILTER_VALIDATE_EMAIL)) {
  251.     $subject = $name;
  252.     // To send HTML mail, the Content-type header must be set.
  253.     $headers = 'MIME-Version: 1.0' . "rn";
  254.     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
  255.     $headers .= 'From:' . $email. "rn"; // Sender's Email
  256.     //$headers .= 'Cc:' . $email. "rn"; // Carbon copy to Sender
  257.     $template = '<div style="padding:50px; color:white;">Hello ,<br/>'
  258.         . '<br/><br/>'
  259.         . 'Name:' .$name.'<br/>'
  260.         . 'Email:' .$email.'<br/>'
  261.         . '<br/>'
  262.         . '</div>';
  263.     $sendmessage = "<div style="background-color:#7E7E7E; color:white;">" . $template . "</div>";
  264.     // Message lines should not exceed 70 characters (PHP rule), so wrap it.
  265.     $sendmessage = wordwrap($sendmessage, 70);
  266.     // Send mail by PHP Mail Function.
  267.     mail($reciver, $subject, $sendmessage, $headers);
  268.     echo "Your Query has been received, We will contact you soon.";
  269. } else {
  270.     echo "<span>* invalid email *</span>";
  271. }
  272.    
  273. <?php
  274. $to = "somebody@example.com, somebodyelse@example.com";
  275. $subject = "HTML email";
  276.  
  277. $message = "
  278.    <html>
  279.    <head>
  280.       <title>HTML email</title>
  281.    </head>
  282.    <body>
  283.      <p>This email contains HTML Tags!</p>
  284.      <table>
  285.        <tr>
  286.         <th>Firstname</th>
  287.         <th>Lastname</th>
  288.        </tr>
  289.        <tr>
  290.          <td>John</td>
  291.          <td>Doe</td>
  292.        </tr>
  293.      </table>
  294.    </body>
  295.    </html>";
  296.  
  297. // Always set content-type when sending HTML email
  298. $headers = "MIME-Version: 1.0" . "rn";
  299. $headers .= "Content-type:text/html;charset=UTF-8" . "rn";
  300.  
  301. // More headers
  302. $headers .= 'From: <webmaster@example.com>' . "rn";
  303. $headers .= 'Cc: myboss@example.com' . "rn";
  304.  
  305. mail($to,$subject,$message,$headers);
  306. ?>
  307.    
  308. if ($_POST['submit']) {
  309.     $success= mail($to, $subject, $body, $from);
  310.     if($success)
  311.     {
  312.         echo '
  313.         <p>Your message has been sent!</p>
  314.         ';
  315.     } else {
  316.         echo '
  317.         <p>Something went wrong, go back and try again!</p>
  318.         ';
  319.     }
  320. }
  321.    
  322. require 'mail/swift_required.php';
  323.  
  324. $message = Swift_Message::newInstance()
  325.     // The subject of your email
  326.     ->setSubject('Jane Doe sends you a message')
  327.     // The from address(es)
  328.     ->setFrom(array('jane.doe@gmail.com' => 'Jane Doe'))
  329.     // The to address(es)
  330.     ->setTo(array('frank.stevens@gmail.com' => 'Frank Stevens'))
  331.     // Here, you put the content of your email
  332.     ->setBody('<h3>New message</h3><p>Here goes the rest of my message</p>', 'text/html');
  333.  
  334. if (Swift_Mailer::newInstance(Swift_MailTransport::newInstance())->send($message)) {
  335.     echo json_encode([
  336.         "status" => "OK",
  337.         "message" => 'Your message has been sent!'
  338.     ], JSON_PRETTY_PRINT);
  339. } else {
  340.     echo json_encode([
  341.         "status" => "error",
  342.         "message" => 'Oops! Something went wrong!'
  343.     ], JSON_PRETTY_PRINT);
  344. }
  345.    
  346. <?php
  347.  
  348.     error_reporting(0);
  349.     $name = $_POST['name'];
  350.     $email = $_POST['email'];
  351.     $message = $_POST['message'];
  352.     $from = 'From: yoursite.com';
  353.     $to = 'contact@yoursite.com';
  354.     $subject = 'Customer Inquiry';
  355.     $body = "From: $namen E-Mail: $emailn Message:n $message";
  356.  
  357.  
  358.     if ($_POST['submit']){
  359.                 if (!(empty($_POST['name']))) {
  360.                         if (!(empty($_POST['email']))){
  361.                             if (!(empty($_POST['message']))){
  362.                                 mail ($to, $subject, $body, $from);
  363.                                 echo '<p>Your message has been sent!</p>';
  364.                             }else{
  365.                                 echo '<p>Fill your message please.</p>';}
  366.                         }else {
  367.                             echo '<p>Fill your email please.</p>';}
  368.                 }else{
  369.                     echo '<p>Fill your name please.</p>';}              
  370.     }else{
  371.             echo '<p>Fill the form.</p>';}
  372. ?>
  373.    
  374. <html>
  375.     <form method="post" action="?">
  376.         <table>
  377.             <tr><td>Name</td><td><input type='text' name='name' id='name'/></td></tr>
  378.             <tr><td>Email</td><td><input type='text' name='email' id='email'/></td></tr>
  379.             <tr><td>Message</td><td><input type='text' name='message' id='message'/></td></tr>
  380.             <tr><td></td><td><input type='submit' name='submit' id='submit'/></td></tr>
  381.         </table>
  382.     </form>
  383. </html>
  384.    
  385. $name = $_POST['name'];
  386. $email = $_POST['email'];
  387. $message = $_POST['message'];
  388. $from = 'From: yoursite.com';
  389. $to = 'contact@yoursite.com';
  390. $subject = 'Customer Inquiry';
  391. $body = "From: $namen E-Mail: $emailn Message:n $message";
  392.    
  393. sudo apt-get install sendmail
  394.    
  395. From: myapp@example.com
  396. To: mymail@example.com
  397. Subject: Test mail via sendmail.
  398.  
  399. Text body.
  400.    
  401. root=mymail@example.com
  402. mailhub=smtp.yandex.ru:465
  403. FromLineOverride=YES
  404. UseTLS=YES
  405. AuthUser=abcde@yandex.ru
  406. AuthPass=password
  407.    
  408. <?php
  409.     $to      = 'nobody@example.com';
  410.     $subject = 'the subject';
  411.     $message = 'hello';
  412.     $headers = 'From: webmaster@example.com' . "rn" .
  413.         'Reply-To: webmaster@example.com' . "rn" .
  414.         'X-Mailer: PHP/' . phpversion();
  415.  
  416.     mail($to, $subject, $message, $headers);
  417. ?>
  418.    
  419. include "libmail.php";
  420. $m = new Mail(); // create the mail
  421. $m->From( $_POST['form'] );
  422. $m->To( $_POST['to'] );
  423. $m->Subject( $_POST['subject'] );
  424. $m->Body( $_POST['body'] );
  425. $m->Cc( $_POST['cc']);
  426. $m->Priority(4);
  427. //  attach a file of type image/gif to be displayed in the message if possible
  428. $m->Attach( "/home/leo/toto.gif", "image/gif", "inline" );
  429. $m->Send(); // send the mail
  430. echo "Mail was sent:"
  431. echo $m->Get(); // show the mail source
  432.    
  433. <?php
  434. $to = "somebody@example.com";
  435. $subject = "My subject";
  436. $txt = "Hello world!";
  437. $headers = "From: webmaster@example.com" . "rn" .
  438. "CC: somebodyelse@example.com";
  439.  
  440. mail($to,$subject,$txt,$headers);
  441. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement