SSL Part 2: PHP mail function: Difference between revisions
Jump to navigation
Jump to search
SSL Part 2: PHP mail function (view source)
Revision as of 17:36, 24 November 2010
, 24 November 2010Reverted edits by Upazixorys (Talk); changed back to last version by Ric
Upazixorys (talk | contribs) No edit summary |
m (Reverted edits by Upazixorys (Talk); changed back to last version by Ric) |
||
Line 1: | Line 1: | ||
<span id="top"></span> | |||
<div style="padding:0;margin:0; border-bottom:3px inset #000000"> | |||
{| | {| | ||
| [[Image:uc_small_logo.gif | MPG UniCenter]] || | | [[Image:uc_small_logo.gif | MPG UniCenter]] || | ||
Line 16: | Line 15: | ||
|} | |} | ||
</div> | |||
{| cellpadding= | {| cellpadding="2" | ||
| | | | ||
__TOC__ | __TOC__ | ||
|| | || | ||
'''PHP mail function problem''' | '''PHP mail function problem'''<br>'''Signed Certificate Project'''<br>Uniform Server 3.5-Apollo''' | ||
|} | |} | ||
With your e-mail server working I suppose one of the first things to try is PHP’s mail function. A very simple looking function with the power to make you rip your hair out when you discover it does not work. | With your e-mail server working I suppose one of the first things to try is PHP’s mail function. A very simple looking function with the power to make you rip your hair out when you discover it does not work. | ||
Line 35: | Line 34: | ||
|- | |- | ||
| | | | ||
{| cellpadding= | {| cellpadding="2" cellspacing="1" style="background:#000000;" | ||
|- style= | |- style="background:#e8e8e8;" | ||
! mail_test_1.php | ! mail_test_1.php | ||
|- style= | |- style="background:#f5f5f5;" | ||
| | | | ||
<pre style="border:none"> | |||
<html> | |||
<head><title>Mail Test 1</title></head> | |||
<body> | |||
<?php | |||
$to_email = | $to_email = "postmaster@mpg123.no-ip.org"; | ||
$subject = | $subject = "Mail Test 1"; | ||
$message = | $message = "Basic PHP mail function"; | ||
if (mail($to_email,$subject,$message)){ | if (mail($to_email,$subject,$message)){ | ||
echo ' | echo '<br>Mail accepted for delivery<br>'; | ||
} | } | ||
else{ | else{ | ||
echo 'There was an error. Mail not accepted for delivery'; | echo 'There was an error. Mail not accepted for delivery'; | ||
} | } | ||
? | ?> | ||
</body> | |||
</html> | |||
</pre> | |||
|} | |} | ||
|valign= | |valign="top"| | ||
'''Test 1:''' | '''Test 1:''' | ||
{| | {| | ||
|- | |- | ||
|'''Run script:'''||Type into your browser | |'''Run script:'''||Type into your browser <nowiki>http://localhost/mail_test_1.php</nowiki> | ||
|- | |- | ||
|'''Result:'''||Mail accepted for delivery | |'''Result:'''||Mail accepted for delivery | ||
|- | |- | ||
|'''Email client:'''||style= | |'''Email client:'''||style="background:#e8e8e8;"|From: me@localhost.com | ||
|- | |- | ||
|& | | ||Subject: Mail Test 1 | ||
|} | |} | ||
Line 94: | Line 93: | ||
|- | |- | ||
| | | | ||
{| cellpadding= | {| cellpadding="2" cellspacing="1" style="background:#000000;" | ||
|- style= | |- style="background:#e8e8e8;" | ||
! mail_test_2.php | ! mail_test_2.php | ||
|- style= | |- style="background:#f5f5f5;" | ||
| | | | ||
<pre style="border:none"> | |||
<html> | |||
<head><title>Mail Test 1</title></head> | |||
<body> | |||
<?php | |||
$to_email = | $to_email = "real_name@real_domain"; | ||
$subject = | $subject = "Mail Test 2"; | ||
$message = | $message = "Basic PHP mail function"; | ||
if (mail($to_email,$subject,$message)){ // Line 10 | if (mail($to_email,$subject,$message)){ // Line 10 | ||
echo ' | echo '<br>Mail accepted for delivery<br>'; | ||
} | } | ||
else{ | else{ | ||
echo 'There was an error. Mail not accepted for delivery'; | echo 'There was an error. Mail not accepted for delivery'; | ||
} | } | ||
? | ?> | ||
</body> | |||
</html> | |||
</pre> | |||
|} | |} | ||
|valign= | |valign="top"| | ||
'''Test 2:''' | '''Test 2:''' | ||
{| | {| | ||
|- | |- | ||
|'''Run script:'''||Type into your browser | |'''Run script:'''||Type into your browser <nowiki>http://localhost/mail_test_2.php</nowiki> | ||
|- | |- | ||
|'''Result:'''||style= | |'''Result:'''||style="background:#e8e8e8;"| | ||
'''Warning: mail() [function.mail]: SMTP server response: 550 Delivery is not allowed to this address. in W:\www\mail_test_1.php on line 10''' | '''Warning: mail() [function.mail]: SMTP server response: 550 Delivery is not allowed to this address. in W:\www\mail_test_1.php on line 10'''<br> | ||
There was an error. Mail not accepted for delivery | There was an error. Mail not accepted for delivery | ||
|} | |} | ||
Line 146: | Line 145: | ||
| | | | ||
[[Image:Uc_hms_config_8.gif]] | [[Image:Uc_hms_config_8.gif]] | ||
|valign= | |valign="top"| | ||
A quick and disastrous solution is to check the bottom box and allow external-to-external relaying. | A quick and disastrous solution is to check the bottom box and allow external-to-external relaying. | ||
Line 168: | Line 167: | ||
| | | | ||
[[Image:Uc_hms_php_mail_1.gif]] | [[Image:Uc_hms_php_mail_1.gif]] | ||
|valign= | |valign="top"| | ||
'''Create new domain:''' | '''Create new domain:''' | ||
Line 184: | Line 183: | ||
| | | | ||
[[Image:Uc_hms_php_mail_2.gif]] | [[Image:Uc_hms_php_mail_2.gif]] | ||
|valign= | |valign="top"| | ||
'''Create new account:''' | '''Create new account:''' | ||
Line 203: | Line 202: | ||
{| | {| | ||
|- | |- | ||
|'''Run script:'''|| Type into your browser | |'''Run script:'''|| Type into your browser <nowiki>http://localhost/mail_test_2.php</nowiki> | ||
|- | |- | ||
|'''Result:'''||styple= | |'''Result:'''||styple="background:#efefef"| '''Mail accepted for delivery''' Indicates mail was sent (Script is working!) | ||
|- | |- | ||
|'''Mail Client:'''& | |'''Mail Client:''' || Wait for the mail to be delivered. After a reasonable time refresh your e-mail client. | ||
|- | |- | ||
|'''Result:'''||styple= | |'''Result:'''||styple="background:#efefef"|From: '''me2@localhost.com''' | ||
|- | |- | ||
|& | | ||Subject: Mail Test 2 | ||
|} | |} | ||
Line 232: | Line 231: | ||
|- | |- | ||
| | | | ||
{| cellpadding= | {| cellpadding="2" cellspacing="1" style="background:#000000;" | ||
|- style= | |- style="background:#e8e8e8;" | ||
! mail_test_3.php | ! mail_test_3.php | ||
|- style= | |- style="background:#f5f5f5;" | ||
| | | | ||
<pre style="border:none"> | |||
<html> | |||
<head><title>Mail Test 3</title></head> | |||
<body> | |||
<?php | |||
$to_email = | $to_email = "real_name@real_domain"; | ||
$subject = | $subject = "Mail Test 3"; | ||
$message = | $message = "Basic PHP mail function"; | ||
$from = | $from = "fred@someone.com"; | ||
$headers = | $headers ="From: ". $from . "\r\n"; | ||
if (mail($to_email,$subject,$message,$headers)){ | if (mail($to_email,$subject,$message,$headers)){ | ||
echo ' | echo '<br>Mail accepted for delivery<br>'; | ||
} | } | ||
else{ | else{ | ||
echo 'There was an error. Mail not accepted for delivery'; | echo 'There was an error. Mail not accepted for delivery'; | ||
} | } | ||
? | ?> | ||
</body> | |||
</html> | |||
</pre> | |||
|} | |} | ||
|valign= | |valign="top"| | ||
'''Test 3:''' | '''Test 3:''' | ||
{| | {| | ||
Line 274: | Line 273: | ||
{| | {| | ||
|- | |- | ||
|valign= | |valign="top"|'''Run script:'''||Type into your browser <nowiki>http://localhost/mail_test_3.php</nowiki><br>Wait a short time for the mail to be delivered and then read your e-mail. | ||
|- | |- | ||
|'''Result:'''||style= | |'''Result:'''||style="background:#efefef"|The from address will display '''fred@someone.com''' | ||
|} | |} | ||
|} | |} |