Last active
June 30, 2019 10:42
-
-
Save irahulsaini/7db136cd6876b0c5706a150cc82dc8e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php error_reporting(0); $mail = array(); | |
/* -------------------------------------- | |
| github: https://gist.github.com/irahulsaini/7db136cd6876b0c5706a150cc82dc8e4/ | |
| documents: https://www.irahulsaini.com/2019/06/simple-contact-form-php.html | |
*/ | |
$mail['to'] = 'contact@irahulsaini.com'; //replace with your email, multiple email id seperated by comma | |
$mail['from_name'] = 'Rahul Saini'; //replace with yours | |
$mail['from_mail'] = 'hello@irahulsaini.com'; //replace with yours | |
$mail['subject'] = "A New Contact Message Received"; | |
$mail['message'] = ' | |
<p><b>Details of sender:</b></p> | |
{fields} | |
- Thanks & Regards | |
'; | |
$mail2['enable'] = 1; | |
$mail2['to'] = '{email}'; | |
$mail2['subject'] = 'Thanks for contacting us'; | |
$mail2['message'] = ' | |
<p> | |
Dear {name},<br/> | |
Thanks for Contacting us, our team will respond your message within 1-2 business days<br/> | |
<br/> | |
<b>- Thanks & Regards</b><br/> | |
- Rahul Saini<br/> | |
<a href="mailto:hello@irahulsaini.com">hello@irahulsaini.com</a> | |
<a href="https://www.irahulsaini.com">www.weforit.com</a> | |
'; | |
/* | |
****************************************** | |
******** DON'T MODIFY CODE BELOW ********* | |
****************************************** | |
*/ | |
/* Mail headers */ | |
$mail['headers'][] = "MIME-Version: 1.0" . "\r\n"; | |
$mail['headers'][] = "Content-type:text/html;charset=UTF-8" . "\r\n"; | |
$mail['headers'][] = "From: ".$mail['from_name']." <".$mail['from_mail'].">"."\r\n"; | |
$mail['headers'] = join('',$mail['headers']); | |
if($_SERVER['REQUEST_METHOD'] == 'POST'){ | |
$field = array(); | |
foreach($_POST as $key => $value){ | |
$key = htmlentities(trim(utf8_encode(strip_tags($key)))); | |
$value = htmlentities(trim(utf8_encode(strip_tags($value)))); | |
$field[$key] = $value; | |
} | |
echo send_mail($field); | |
} | |
function send_mail($fields){ | |
global $mail,$mail2; | |
$m = '<html><head><title>'.$mail['subject'].'</title></head><body><table>'; | |
if(is_array($fields) && count($fields) > 0){ | |
foreach($fields as $key => $value){ | |
if(!$value){ | |
continue; | |
} | |
$m .= ' | |
<tr> | |
<th align="left" valign="top">'.ucwords(str_replace(array('_','-'),' ',$key)).'</th> | |
<th valign="top">:</th> | |
<td valign="top">'.nl2br($value).'</td> | |
</tr> | |
'; | |
} | |
} | |
$m .= '</table></body></html>'; | |
$mail['message'] = str_replace('{fields}',$m,$mail['message']); | |
$to = explode(",",$mail['to']); | |
$status = 0; | |
foreach($to as $_to){ | |
$_to = strtolower($_to); | |
if(!filter_var($_to,FILTER_VALIDATE_EMAIL)){ | |
continue; | |
} | |
//require_once 'PHPMailer.php'; /* COMING SOON */ | |
if(mail($_to,$mail['subject'],$mail['message'],$mail['headers'],'-f'.$mail['from_mail'])){ | |
$status = 1; | |
} | |
} | |
if($status == 1 && $mail2['enable'] == 1){ | |
//send second mail | |
$search = array(); | |
$replace = array(); | |
foreach($fields as $key => $value){ | |
$search[] = '{'.$key.'}'; | |
$replace[] = $value; | |
} | |
$mail2['to'] = str_replace($search,$replace,$mail2['to']); | |
$mail2['subject'] = str_replace($search,$replace,$mail2['subject']); | |
$mail2['message'] = str_replace($search,$replace,$mail2['message']); | |
mail($mail2['to'],$mail2['subject'],$mail2['message'],$mail['headers'],'-f'.$mail['from_mail']); | |
} | |
return $status; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment