· 9 years ago · Feb 14, 2017, 03:10 PM
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
19error_reporting(-1);
20ini_set('display_errors', 'On');
21set_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);
28mail($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 ....
37mail($recipient, $subject, $message, $headers); // $recipient should be $to
38
39mail('user@example.com', $subject, $message, $headers);
40
41ini_set("mail.log", "/tmp/mail.log");
42ini_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
51if($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
58function 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
101mail('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
118mail($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
137if($this->email->send())
138{
139 //conditional true
140}
141
142<?php
143 $name = $_POST['name'];
144 $email = $_POST['email'];
145 $message = $_POST['message'];
146 $from = 'From: yoursite.com';
147 $to = 'contact@yoursite.com';
148 $subject = 'Customer Inquiry';
149 $body = "From:" .$name."rn E-Mail:" .$email."rn Message:rn" .$message;
150
151if (isset($_POST['submit']))
152{
153 if (mail ($to, $subject, $body, $from))
154 {
155 echo '<p>Your message has been sent!</p>';
156 }
157 else
158 {
159 echo '<p>Something went wrong, go back and try again!</p>';
160 }
161}
162
163?>
164
165<?php
166 $SmtpServer="smtp.*.*";
167 $SmtpPort="2525"; //default
168 $SmtpUser="***";
169 $SmtpPass="***";
170?>
171
172<?php
173class SMTPClient
174{
175
176 function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
177 {
178
179 $this->SmtpServer = $SmtpServer;
180 $this->SmtpUser = base64_encode ($SmtpUser);
181 $this->SmtpPass = base64_encode ($SmtpPass);
182 $this->from = $from;
183 $this->to = $to;
184 $this->subject = $subject;
185 $this->body = $body;
186
187 if ($SmtpPort == "")
188 {
189 $this->PortSMTP = 25;
190 }
191 else
192 {
193 $this->PortSMTP = $SmtpPort;
194 }
195 }
196
197 function SendMail ()
198 {
199 $newLine = "rn";
200 $headers = "MIME-Version: 1.0" . $newLine;
201 $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
202
203 if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP))
204 {
205 fputs ($SMTPIN, "EHLO ".$HTTP_HOST."rn");
206 $talk["hello"] = fgets ( $SMTPIN, 1024 );
207 fputs($SMTPIN, "auth loginrn");
208 $talk["res"]=fgets($SMTPIN,1024);
209 fputs($SMTPIN, $this->SmtpUser."rn");
210 $talk["user"]=fgets($SMTPIN,1024);
211 fputs($SMTPIN, $this->SmtpPass."rn");
212 $talk["pass"]=fgets($SMTPIN,256);
213 fputs ($SMTPIN, "MAIL FROM: <".$this->from.">rn");
214 $talk["From"] = fgets ( $SMTPIN, 1024 );
215 fputs ($SMTPIN, "RCPT TO: <".$this->to.">rn");
216 $talk["To"] = fgets ($SMTPIN, 1024);
217 fputs($SMTPIN, "DATArn");
218 $talk["data"]=fgets( $SMTPIN,1024 );
219 fputs($SMTPIN, "To: <".$this->to.">rnFrom: <".$this->from.">rn".$headers."nnSubject:".$this->subject."rnrnrn".$this->body."rn.rn");
220 $talk["send"]=fgets($SMTPIN,256);
221 //CLOSE CONNECTION AND EXIT ...
222 fputs ($SMTPIN, "QUITrn");
223 fclose($SMTPIN);
224 //
225 }
226 return $talk;
227 }
228}
229?>
230
231<?php
232include('SMTPconfig.php');
233include('SMTPmail.php');
234if($_SERVER["REQUEST_METHOD"] == "POST")
235{
236 $to = "";
237 $from = $_POST['email'];
238 $subject = "Enquiry";
239 $body = $_POST['name'].'</br>'.$_POST['companyName'].'</br>'.$_POST['tel'].'</br>'.'<hr />'.$_POST['message'];
240 $SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
241 $SMTPChat = $SMTPMail->SendMail();
242}
243?>
244
245$name = $_POST['name'];
246$email = $_POST['email'];
247$reciver = '/* Reciver Email address */';
248if (filter_var($reciver, FILTER_VALIDATE_EMAIL)) {
249 $subject = $name;
250 // To send HTML mail, the Content-type header must be set.
251 $headers = 'MIME-Version: 1.0' . "rn";
252 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
253 $headers .= 'From:' . $email. "rn"; // Sender's Email
254 //$headers .= 'Cc:' . $email. "rn"; // Carbon copy to Sender
255 $template = '<div style="padding:50px; color:white;">Hello ,<br/>'
256 . '<br/><br/>'
257 . 'Name:' .$name.'<br/>'
258 . 'Email:' .$email.'<br/>'
259 . '<br/>'
260 . '</div>';
261 $sendmessage = "<div style="background-color:#7E7E7E; color:white;">" . $template . "</div>";
262 // Message lines should not exceed 70 characters (PHP rule), so wrap it.
263 $sendmessage = wordwrap($sendmessage, 70);
264 // Send mail by PHP Mail Function.
265 mail($reciver, $subject, $sendmessage, $headers);
266 echo "Your Query has been received, We will contact you soon.";
267} else {
268 echo "<span>* invalid email *</span>";
269}
270
271$mail->SMTPDebug = 2;
272
273if ($_POST['submit']) {
274 $success= mail($to, $subject, $body, $from);
275 if($success)
276 {
277 echo '
278 <p>Your message has been sent!</p>
279 ';
280 } else {
281 echo '
282 <p>Something went wrong, go back and try again!</p>
283 ';
284 }
285}
286
287try this
288<?php
289$to = "somebody@example.com, somebodyelse@example.com";
290$subject = "HTML email";
291
292$message = "
293<html>
294 <head>
295 <title>HTML email</title>
296 </head>
297 <body>
298 <p>This email contains HTML Tags!</p>
299 <table>
300 <tr>
301 <th>Firstname</th>
302 <th>Lastname</th>
303 </tr>
304 <tr>
305 <td>John</td>
306 <td>Doe</td>
307 </tr>
308 </table>
309 </body>
310 </html>
311";
312
313// Always set content-type when sending HTML email
314$headers = "MIME-Version: 1.0" . "rn";
315$headers .= "Content-type:text/html;charset=UTF-8" . "rn";
316
317// More headers
318$headers .= 'From: <webmaster@example.com>' . "rn";
319$headers .= 'Cc: myboss@example.com' . "rn";
320
321mail($to,$subject,$message,$headers);
322?>
323
324require 'mail/swift_required.php';
325
326$message = Swift_Message::newInstance()
327 // The subject of your email
328 ->setSubject('Jane Doe sends you a message')
329 // The from address(es)
330 ->setFrom(array('jane.doe@gmail.com' => 'Jane Doe'))
331 // The to address(es)
332 ->setTo(array('frank.stevens@gmail.com' => 'Frank Stevens'))
333 // Here, you put the content of your email
334 ->setBody('<h3>New message</h3><p>Here goes the rest of my message</p>', 'text/html');
335
336if (Swift_Mailer::newInstance(Swift_MailTransport::newInstance())->send($message)) {
337 echo json_encode([
338 "status" => "OK",
339 "message" => 'Your message has been sent!'
340 ], JSON_PRETTY_PRINT);
341} else {
342 echo json_encode([
343 "status" => "error",
344 "message" => 'Oops! Something went wrong!'
345 ], JSON_PRETTY_PRINT);
346}
347
348<?php
349
350 error_reporting(0);
351 $name = $_POST['name'];
352 $email = $_POST['email'];
353 $message = $_POST['message'];
354 $from = 'From: yoursite.com';
355 $to = 'contact@yoursite.com';
356 $subject = 'Customer Inquiry';
357 $body = "From: $namen E-Mail: $emailn Message:n $message";
358
359
360 if ($_POST['submit']){
361 if (!(empty($_POST['name']))) {
362 if (!(empty($_POST['email']))){
363 if (!(empty($_POST['message']))){
364 mail ($to, $subject, $body, $from);
365 echo '<p>Your message has been sent!</p>';
366 }else{
367 echo '<p>Fill your message please.</p>';}
368 }else {
369 echo '<p>Fill your email please.</p>';}
370 }else{
371 echo '<p>Fill your name please.</p>';}
372 }else{
373 echo '<p>Fill the form.</p>';}
374?>
375
376<html>
377 <form method="post" action="?">
378 <table>
379 <tr><td>Name</td><td><input type='text' name='name' id='name'/></td></tr>
380 <tr><td>Email</td><td><input type='text' name='email' id='email'/></td></tr>
381 <tr><td>Message</td><td><input type='text' name='message' id='message'/></td></tr>
382 <tr><td></td><td><input type='submit' name='submit' id='submit'/></td></tr>
383 </table>
384 </form>
385</html>
386
387$name = $_POST['name'];
388$email = $_POST['email'];
389$message = $_POST['message'];
390$from = 'From: yoursite.com';
391$to = 'contact@yoursite.com';
392$subject = 'Customer Inquiry';
393$body = "From: $namen E-Mail: $emailn Message:n $message";
394
395You need @mail function and also SMTP configration for sending mail. Here is the full code for this **WITH MYSQL QUERY**
396
397
398 <?php
399 isset($_POST['send'])){
400 $name = $_POST['name'];
401 $email = $_POST['email'];
402 $contact = $_POST['contact'];
403 $comment = $_POST['comment'];
404 $email_to = 'someone@gmail.com';
405
406
407 $sql_query = "INSERT INTO admin_contact (name, email, contact, comment) VALUES ('$name','$email','$contact','$comment')";
408
409 if($link->query($sql_query) === TRUE){
410 //EDIT THE 2 LINES BELOW AS REQUIRED
411
412 $email_to;
413 $email_from = $email; //FROM WHOM MAIL HAS COME
414 $email_subject = "Your email subject line";
415
416
417
418
419
420 function died($error) {
421
422 //your error code can go here
423
424 echo "We are very sorry, but there were error(s) found with the form you submitted. ";
425
426 echo "These errors appear below.<br /><br />";
427
428 echo $error."<br /><br />";
429
430 echo "Please go back and fix these errors.<br /><br />";
431
432 die();
433
434 }
435
436
437
438 // validation expected data exists
439
440 if(!isset($_POST['name']) ||
441
442
443
444 !isset($_POST['email']) ||
445
446 !isset($_POST['contact']) ||
447
448 !isset($_POST['comment'])) {
449
450 died('We are sorry, but there appears to be a problem with the form you submitted.');
451
452 }
453
454
455
456 $name = $_POST['name']; // required
457
458
459 $email= $_POST['email']; // required
460
461 $contact = $_POST['contact']; // required
462
463 $comment = $_POST['comment']; // required
464
465
466
467 $error_message = "";
468
469 $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
470
471 if(!preg_match($email_exp,$email_from)) {
472
473 $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
474
475 }
476
477 $string_exp = "/^[A-Za-z .'-]+$/";
478
479 if(!preg_match($string_exp,$name)) {
480
481 $error_message .= 'The Name you entered does not appear to be valid.<br />';
482
483 }
484
485
486
487 if(strlen($comment) < 2) {
488
489 $error_message .= 'The Comments you entered do not appear to be valid.<br />';
490
491 }
492
493 if(strlen($error_message) > 0) {
494
495 died($error_message);
496
497 }
498
499 $email_message = "Form details below.nn";
500
501
502
503 function clean_string($string) {
504
505 $bad = array("content-type","bcc:","to:","cc:","href");
506
507 return str_replace($bad,"",$string);
508
509 }
510
511
512
513 $email_message .= "Name: ".clean_string($name)."n";
514
515
516
517 $email_message .= "Email: ".clean_string($email_from)."n";
518
519 $email_message .= "Telephone: ".clean_string($contact)."n";
520
521 $email_message .= "Comments: ".clean_string($comment)."n";
522
523
524
525
526
527 // create email headers
528
529 $headers = 'From: '.$email_from."rn".
530
531 'Reply-To: '.$email_to."rn" .
532
533 'X-Mailer: PHP/' . phpversion();
534
535 @mail($email_to, $email_subject, $email_message, $headers);
536
537
538 if(@mail){
539 ?>
540 <center class="w3-panel w3-green">
541 <span onclick="this.parentElement.style.display='none'" class="w3-closebtn">×</span>
542 <h3>Success!</h3>
543 <p>Thank You For Contact us.</p>
544 <p>We Will soon in touch with you</p>
545 <p><a href="../contact.php">Click Here</a> to Return back.</p>
546 </center>
547 <?php
548 }
549 else
550 {
551 ?>
552 <center class="w3-panel w3-red">
553 <span onclick="this.parentElement.style.display='none'" class="w3-closebtn">×</span>
554 <h3>Failed!</h3>
555 <p>There Was a Problem Sending you mail.</p>
556 <p>Try By removing <strong>(,?/""}])</strong>.</p>
557 <p><a href="../contact.php">Click Here</a> to Return back.</p>
558 </center>
559 <?php
560 }
561 }
562 else
563 {
564 ?>
565 <div class="container">
566 <div class="w3-panel w3-red">
567 <span onclick="this.parentElement.style.display='none'" class="w3-closebtn">×</span>
568 <h3><?php echo "Failed to send Message ".$sql_query. "<br> " .$link->error;?></h3><br>
569
570 </div>
571
572 <center class="w3-panel w3-orange">
573 <span onclick="this.parentElement.style.display='none'" class="w3-closebtn">×</span>
574 <h3>There Was a Problem Sending you mail.</p>
575 <p>Try By removing <strong>(,?/""}])</strong>.</p>
576 <p><a href="../contact.php">Click Here</a> to Return back.</p>
577 </center>
578 </div>
579 <?php
580 }
581
582 }
583 $link->close();
584?>
585</body>
586</html>
587
588$myText = (string)$myVar;