Send Mail using mail function in PHP
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php $to = "hello@codebucket.in"; $subject = "Test Mail"; $body = "Body of your message here you can use HTML too. e.g. <br> <b> Bold </b>"; $headers = "From: example@yousite.com\r\n"; $headers .= "Reply-To: example@yoursite.com\r\n"; $headers .= "Return-Path: example@yoursite.com\r\n"; $headers .= "X-Mailer: PHP5\n"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subject,$body,$headers); ?> |
Short verison for mail function in PHP
1 2 3 4 5 6 7 8 |
<?php $to = "info@example.com"; $subject = "My subject"; $msg = "Hello world!"; $headers = "From: webmaster@example.com" . "\r\n" . "CC: somebodyelse@example.com"; mail($to,$subject,$msg,$headers); ?> |
Get Remote IP Address in PHP
1 2 3 4 |
<?php $ip = $_SERVER['REMOTE_ADDR']; echo $ip; ?> |
The above code will not work in case your client is behind proxy server. In that case use below function to get real IP address of client.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } echo $ip; ?> |
Email validation snippet in […]
Continue reading