Guest User

Untitled

a guest
Jan 12th, 2017
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.60 KB | None | 0 0
  1. <?php
  2. $name = $_POST['name'];
  3. $email = $_POST['email'];
  4. $message = $_POST['message'];
  5. $from = 'From: yoursite.com';
  6. $subject = 'Customer Inquiry';
  7. $body = "From: $namen E-Mail: $emailn Message:n $message";
  8.  
  9. if ($_POST['submit']) {
  10. if (mail ($to, $subject, $body, $from)) {
  11. echo '<p>Your message has been sent!</p>';
  12. } else {
  13. echo '<p>Something went wrong, go back and try again!</p>';
  14. }
  15. }
  16. ?>
  17.  
  18. error_reporting(-1);
  19. ini_set('display_errors', 'On');
  20. set_error_handler("var_dump");
  21.  
  22. $headers = array("From: [email protected]",
  23. "Reply-To: [email protected]",
  24. "X-Mailer: PHP/" . PHP_VERSION
  25. );
  26. $headers = implode("rn", $headers);
  27. mail($to, $subject, $message, $headers);
  28.  
  29. $headers = array("From [email protected]", // missing colon
  30. "Reply To: [email protected]", // missing hyphen
  31. "X-Mailer: "PHP"/" . PHP_VERSION // bad quotes
  32. );
  33.  
  34. // other variables ....
  35. mail($recipient, $subject, $message, $headers); // $recipient should be $to
  36.  
  37. mail('[email protected]', $subject, $message, $headers);
  38.  
  39. ini_set("mail.log", "/tmp/mail.log");
  40. ini_set("mail.add_x_header", TRUE);
  41.  
  42. $header = "From: [email protected]";
  43. $header.= "MIME-Version: 1.0rn";
  44. $header.= "Content-Type: text/html; charset=ISO-8859-1rn";
  45. $header.= "X-Priority: 1rn";
  46.  
  47. $status = mail($to, $subject, $message, $header);
  48.  
  49. if($status)
  50. {
  51. echo '<p>Your mail has been sent!</p>';
  52. } else {
  53. echo '<p>Something went wrong, Please try again!</p>';
  54. }
  55.  
  56. function send_mail($email, $recipient_name, $message='')
  57. {
  58. require("phpmailer/class.phpmailer.php");
  59.  
  60. $mail = new PHPMailer();
  61.  
  62. $mail->CharSet="utf-8";
  63. $mail->IsSMTP(); // set mailer to use SMTP
  64. $mail->Host = "mail.example.com"; // specify main and backup server
  65. $mail->SMTPAuth = true; // turn on SMTP authentication
  66. $mail->Username = "myusername"; // SMTP username
  67. $mail->Password = "p@ssw0rd"; // SMTP password
  68.  
  69. $mail->From = "[email protected]";
  70. $mail->FromName = "System-Ad";
  71. $mail->AddAddress($email, $recipient_name);
  72.  
  73. $mail->WordWrap = 50; // set word wrap to 50 characters
  74. $mail->IsHTML(true); // set email format to HTML (true) or plain text (false)
  75.  
  76. $mail->Subject = "This is a Sampleenter code here Email";
  77. $mail->Body = $message;
  78. $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
  79. $mail->AddEmbeddedImage('images/logo.png', 'logo', 'logo.png');
  80. $mail->addAttachment('files/file.xlsx');
  81.  
  82. if(!$mail->Send())
  83. {
  84. echo "Message could not be sent. <p>";
  85. echo "Mailer Error: " . $mail->ErrorInfo;
  86. exit;
  87. }
  88.  
  89. echo "Message has been sent";
  90. }
  91.  
  92. <?php
  93. $name = $_POST['name'];
  94. $email = $_POST['email'];
  95. $message = $_POST['message'];
  96. $from = 'From: yoursite.com';
  97. $subject = 'Customer Inquiry';
  98. $body = "From: $namen E-Mail: $emailn Message:n $message";
  99.  
  100. $headers .= "MIME-Version: 1.0rn";
  101. $headers .= "Content-type: text/htmlrn";
  102. $headers = 'From: [email protected]' . "rn" .
  103. 'Reply-To: [email protected]' . "rn" .
  104. 'X-Mailer: PHP/' . phpversion();
  105.  
  106. mail($to, $subject, $message, $headers);
  107.  
  108. $headers = "MIME-Version: 1.0" . "rn";
  109. $headers .= "Content-type: text/html; charset=iso-8859-1" . "rn";
  110. $headers .= "From: ". $from. "rn";
  111. $headers .= "Reply-To: ". $from. "rn";
  112. $headers .= "X-Mailer: PHP/" . phpversion();
  113. $headers .= "X-Priority: 1" . "rn";
  114.  
  115. mail('[email protected]', $subject, $message, $headers)
  116.  
  117. $config = Array(
  118. 'protocol' => 'smtp',
  119. 'smtp_host' => 'mail.domain.com', //your smtp host
  120. 'smtp_port' => 26, //default port smtp
  121. 'smtp_user' => '[email protected]',
  122. 'smtp_pass' => 'password',
  123. 'mailtype' => 'html',
  124. 'charset' => 'iso-8859-1',
  125. 'wordwrap' => TRUE
  126. );
  127. $message = 'Your msg';
  128. $this->load->library('email', $config);
  129. $this->email->from('[email protected]', 'Title');
  130. $this->email->to('[email protected]');
  131. $this->email->subject('Header');
  132. $this->email->message($message);
  133.  
  134. if($this->email->send())
  135. {
  136. //conditional true
  137. }
  138.  
  139. <?php
  140. $name = $_POST['name'];
  141. $email = $_POST['email'];
  142. $message = $_POST['message'];
  143. $from = 'From: yoursite.com';
  144. $subject = 'Customer Inquiry';
  145. $body = "From:" .$name."rn E-Mail:" .$email."rn Message:rn" .$message;
  146.  
  147. if (isset($_POST['submit']))
  148. {
  149. if (mail ($to, $subject, $body, $from))
  150. {
  151. echo '<p>Your message has been sent!</p>';
  152. }
  153. else
  154. {
  155. echo '<p>Something went wrong, go back and try again!</p>';
  156. }
  157. }
  158.  
  159. ?>
  160.  
  161. <?php
  162. $SmtpServer="smtp.*.*";
  163. $SmtpPort="2525"; //default
  164. $SmtpUser="***";
  165. $SmtpPass="***";
  166. ?>
  167.  
  168. <?php
  169. class SMTPClient
  170. {
  171.  
  172. function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
  173. {
  174.  
  175. $this->SmtpServer = $SmtpServer;
  176. $this->SmtpUser = base64_encode ($SmtpUser);
  177. $this->SmtpPass = base64_encode ($SmtpPass);
  178. $this->from = $from;
  179. $this->to = $to;
  180. $this->subject = $subject;
  181. $this->body = $body;
  182.  
  183. if ($SmtpPort == "")
  184. {
  185. $this->PortSMTP = 25;
  186. }
  187. else
  188. {
  189. $this->PortSMTP = $SmtpPort;
  190. }
  191. }
  192.  
  193. function SendMail ()
  194. {
  195. $newLine = "rn";
  196. $headers = "MIME-Version: 1.0" . $newLine;
  197. $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
  198.  
  199. if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
  200. {
  201. fputs ($SMTPIN, "EHLO ".$HTTP_HOST."rn");
  202. $talk["hello"] = fgets ( $SMTPIN, 1024 );
  203. fputs($SMTPIN, "auth loginrn");
  204. $talk["res"]=fgets($SMTPIN,1024);
  205. fputs($SMTPIN, $this->SmtpUser."rn");
  206. $talk["user"]=fgets($SMTPIN,1024);
  207. fputs($SMTPIN, $this->SmtpPass."rn");
  208. $talk["pass"]=fgets($SMTPIN,256);
  209. fputs ($SMTPIN, "MAIL FROM: <".$this->from.">rn");
  210. $talk["From"] = fgets ( $SMTPIN, 1024 );
  211. fputs ($SMTPIN, "RCPT TO: <".$this->to.">rn");
  212. $talk["To"] = fgets ($SMTPIN, 1024);
  213. fputs($SMTPIN, "DATArn");
  214. $talk["data"]=fgets( $SMTPIN,1024 );
  215. fputs($SMTPIN, "To: <".$this->to.">rnFrom: <".$this->from.">rn".$headers."nnSubject:".$this->subject."rnrnrn".$this->body."rn.rn");
  216. $talk["send"]=fgets($SMTPIN,256);
  217. //CLOSE CONNECTION AND EXIT ...
  218. fputs ($SMTPIN, "QUITrn");
  219. fclose($SMTPIN);
  220. //
  221. }
  222. return $talk;
  223. }
  224. }
  225. ?>
  226.  
  227. <?php
  228. include('SMTPconfig.php');
  229. include('SMTPmail.php');
  230. if($_SERVER["REQUEST_METHOD"] == "POST")
  231. {
  232. $to = "";
  233. $from = $_POST['email'];
  234. $subject = "Enquiry";
  235. $body = $_POST['name'].'</br>'.$_POST['companyName'].'</br>'.$_POST['tel'].'</br>'.'<hr />'.$_POST['message'];
  236. $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
  237. $SMTPChat = $SMTPMail->SendMail();
  238. }
  239. ?>
  240.  
  241. $name = $_POST['name'];
  242. $email = $_POST['email'];
  243. $reciver = '/* Reciver Email address */';
  244. if (filter_var($reciver, FILTER_VALIDATE_EMAIL)) {
  245. $subject = $name;
  246. // To send HTML mail, the Content-type header must be set.
  247. $headers = 'MIME-Version: 1.0' . "rn";
  248. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
  249. $headers .= 'From:' . $email. "rn"; // Sender's Email
  250. //$headers .= 'Cc:' . $email. "rn"; // Carbon copy to Sender
  251. $template = '<div style="padding:50px; color:white;">Hello ,<br/>'
  252. . '<br/><br/>'
  253. . 'Name:' .$name.'<br/>'
  254. . 'Email:' .$email.'<br/>'
  255. . '<br/>'
  256. . '</div>';
  257. $sendmessage = "<div style="background-color:#7E7E7E; color:white;">" . $template . "</div>";
  258. // Message lines should not exceed 70 characters (PHP rule), so wrap it.
  259. $sendmessage = wordwrap($sendmessage, 70);
  260. // Send mail by PHP Mail Function.
  261. mail($reciver, $subject, $sendmessage, $headers);
  262. echo "Your Query has been received, We will contact you soon.";
  263. } else {
  264. echo "<span>* invalid email *</span>";
  265. }
  266.  
  267. if ($_POST['submit']) {
  268. $success= mail($to, $subject, $body, $from);
  269. if($success)
  270. {
  271. echo '
  272. <p>Your message has been sent!</p>
  273. ';
  274. } else {
  275. echo '
  276. <p>Something went wrong, go back and try again!</p>
  277. ';
  278. }
  279. }
  280.  
  281. $mail->SMTPDebug = 2;
  282.  
  283. try this
  284. <?php
  285. $subject = "HTML email";
  286.  
  287. $message = "
  288. <html>
  289. <head>
  290. <title>HTML email</title>
  291. </head>
  292. <body>
  293. <p>This email contains HTML Tags!</p>
  294. <table>
  295. <tr>
  296. <th>Firstname</th>
  297. <th>Lastname</th>
  298. </tr>
  299. <tr>
  300. <td>John</td>
  301. <td>Doe</td>
  302. </tr>
  303. </table>
  304. </body>
  305. </html>
  306. ";
  307.  
  308. // Always set content-type when sending HTML email
  309. $headers = "MIME-Version: 1.0" . "rn";
  310. $headers .= "Content-type:text/html;charset=UTF-8" . "rn";
  311.  
  312. // More headers
  313. $headers .= 'From: <[email protected]>' . "rn";
  314. $headers .= 'Cc: [email protected]' . "rn";
  315.  
  316. mail($to,$subject,$message,$headers);
  317. ?>
  318.  
  319. require 'mail/swift_required.php';
  320.  
  321. $message = Swift_Message::newInstance()
  322. // The subject of your email
  323. ->setSubject('Jane Doe sends you a message')
  324. // The from address(es)
  325. ->setFrom(array('[email protected]' => 'Jane Doe'))
  326. // The to address(es)
  327. ->setTo(array('[email protected]' => 'Frank Stevens'))
  328. // Here, you put the content of your email
  329. ->setBody('<h3>New message</h3><p>Here goes the rest of my message</p>', 'text/html');
  330.  
  331. if (Swift_Mailer::newInstance(Swift_MailTransport::newInstance())->send($message)) {
  332. echo json_encode([
  333. "status" => "OK",
  334. "message" => 'Your message has been sent!'
  335. ], JSON_PRETTY_PRINT);
  336. } else {
  337. echo json_encode([
  338. "status" => "error",
  339. "message" => 'Oops! Something went wrong!'
  340. ], JSON_PRETTY_PRINT);
  341. }
  342.  
  343. <?php
  344.  
  345. error_reporting(0);
  346. $name = $_POST['name'];
  347. $email = $_POST['email'];
  348. $message = $_POST['message'];
  349. $from = 'From: yoursite.com';
  350. $subject = 'Customer Inquiry';
  351. $body = "From: $namen E-Mail: $emailn Message:n $message";
  352.  
  353.  
  354. if ($_POST['submit']){
  355. if (!(empty($_POST['name']))) {
  356. if (!(empty($_POST['email']))){
  357. if (!(empty($_POST['message']))){
  358. mail ($to, $subject, $body, $from);
  359. echo '<p>Your message has been sent!</p>';
  360. }else{
  361. echo '<p>Fill your message please.</p>';}
  362. }else {
  363. echo '<p>Fill your email please.</p>';}
  364. }else{
  365. echo '<p>Fill your name please.</p>';}
  366. }else{
  367. echo '<p>Fill the form.</p>';}
  368. ?>
  369.  
  370. <html>
  371. <form method="post" action="?">
  372. <table>
  373. <tr><td>Name</td><td><input type='text' name='name' id='name'/></td></tr>
  374. <tr><td>Email</td><td><input type='text' name='email' id='email'/></td></tr>
  375. <tr><td>Message</td><td><input type='text' name='message' id='message'/></td></tr>
  376. <tr><td></td><td><input type='submit' name='submit' id='submit'/></td></tr>
  377. </table>
  378. </form>
  379. </html>
  380.  
  381. $name = $_POST['name'];
  382. $email = $_POST['email'];
  383. $message = $_POST['message'];
  384. $from = 'From: yoursite.com';
  385. $subject = 'Customer Inquiry';
  386. $body = "From: $namen E-Mail: $emailn Message:n $message";
  387.  
  388. You need @mail function and also SMTP configration for sending mail. Here is the full code for this **WITH MYSQL QUERY**
  389.  
  390.  
  391. <?php
  392. isset($_POST['send'])){
  393. $name = $_POST['name'];
  394. $email = $_POST['email'];
  395. $contact = $_POST['contact'];
  396. $comment = $_POST['comment'];
  397. $email_to = '[email protected]';
  398.  
  399.  
  400. $sql_query = "INSERT INTO admin_contact (name, email, contact, comment) VALUES ('$name','$email','$contact','$comment')";
  401.  
  402. if($link->query($sql_query) === TRUE){
  403. //EDIT THE 2 LINES BELOW AS REQUIRED
  404.  
  405. $email_to;
  406. $email_from = $email; //FROM WHOM MAIL HAS COME
  407. $email_subject = "Your email subject line";
  408.  
  409.  
  410.  
  411.  
  412.  
  413. function died($error) {
  414.  
  415. //your error code can go here
  416.  
  417. echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  418.  
  419. echo "These errors appear below.<br /><br />";
  420.  
  421. echo $error."<br /><br />";
  422.  
  423. echo "Please go back and fix these errors.<br /><br />";
  424.  
  425. die();
  426.  
  427. }
  428.  
  429.  
  430.  
  431. // validation expected data exists
  432.  
  433. if(!isset($_POST['name']) ||
  434.  
  435.  
  436.  
  437. !isset($_POST['email']) ||
  438.  
  439. !isset($_POST['contact']) ||
  440.  
  441. !isset($_POST['comment'])) {
  442.  
  443. died('We are sorry, but there appears to be a problem with the form you submitted.');
  444.  
  445. }
  446.  
  447.  
  448.  
  449. $name = $_POST['name']; // required
  450.  
  451.  
  452. $email= $_POST['email']; // required
  453.  
  454. $contact = $_POST['contact']; // required
  455.  
  456. $comment = $_POST['comment']; // required
  457.  
  458.  
  459.  
  460. $error_message = "";
  461.  
  462. $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
  463.  
  464. if(!preg_match($email_exp,$email_from)) {
  465.  
  466. $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  467.  
  468. }
  469.  
  470. $string_exp = "/^[A-Za-z .'-]+$/";
  471.  
  472. if(!preg_match($string_exp,$name)) {
  473.  
  474. $error_message .= 'The Name you entered does not appear to be valid.<br />';
  475.  
  476. }
  477.  
  478.  
  479.  
  480. if(strlen($comment) < 2) {
  481.  
  482. $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  483.  
  484. }
  485.  
  486. if(strlen($error_message) > 0) {
  487.  
  488. died($error_message);
  489.  
  490. }
  491.  
  492. $email_message = "Form details below.nn";
  493.  
  494.  
  495.  
  496. function clean_string($string) {
  497.  
  498. $bad = array("content-type","bcc:","to:","cc:","href");
  499.  
  500. return str_replace($bad,"",$string);
  501.  
  502. }
  503.  
  504.  
  505.  
  506. $email_message .= "Name: ".clean_string($name)."n";
  507.  
  508.  
  509.  
  510. $email_message .= "Email: ".clean_string($email_from)."n";
  511.  
  512. $email_message .= "Telephone: ".clean_string($contact)."n";
  513.  
  514. $email_message .= "Comments: ".clean_string($comment)."n";
  515.  
  516.  
  517.  
  518.  
  519.  
  520. // create email headers
  521.  
  522. $headers = 'From: '.$email_from."rn".
  523.  
  524. 'Reply-To: '.$email_to."rn" .
  525.  
  526. 'X-Mailer: PHP/' . phpversion();
  527.  
  528. @mail($email_to, $email_subject, $email_message, $headers);
  529.  
  530.  
  531. if(@mail){
  532. ?>
  533. <center class="w3-panel w3-green">
  534. <span onclick="this.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
  535. <h3>Success!</h3>
  536. <p>Thank You For Contact us.</p>
  537. <p>We Will soon in touch with you</p>
  538. <p><a href="../contact.php">Click Here</a> to Return back.</p>
  539. </center>
  540. <?php
  541. }
  542. else
  543. {
  544. ?>
  545. <center class="w3-panel w3-red">
  546. <span onclick="this.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
  547. <h3>Failed!</h3>
  548. <p>There Was a Problem Sending you mail.</p>
  549. <p>Try By removing <strong>(,?/""}])</strong>.</p>
  550. <p><a href="../contact.php">Click Here</a> to Return back.</p>
  551. </center>
  552. <?php
  553. }
  554. }
  555. else
  556. {
  557. ?>
  558. <div class="container">
  559. <div class="w3-panel w3-red">
  560. <span onclick="this.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
  561. <h3><?php echo "Failed to send Message ".$sql_query. "<br> " .$link->error;?></h3><br>
  562.  
  563. </div>
  564.  
  565. <center class="w3-panel w3-orange">
  566. <span onclick="this.parentElement.style.display='none'" class="w3-closebtn">&times;</span>
  567. <h3>There Was a Problem Sending you mail.</p>
  568. <p>Try By removing <strong>(,?/""}])</strong>.</p>
  569. <p><a href="../contact.php">Click Here</a> to Return back.</p>
  570. </center>
  571. </div>
  572. <?php
  573. }
  574.  
  575. }
  576. $link->close();
  577. ?>
  578. </body>
  579. </html>
  580.  
  581. $myText = (string)$myVar;
Advertisement
Add Comment
Please, Sign In to add comment