PHP mail function: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Major grammar change, and some rewriting for clarity,)
No edit summary
Line 1: Line 1:
<span id="top"></span>
----
<div style="padding:0;margin:0; border-bottom:3px inset #000000">
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
----
=[http://ovarynetyv.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
----
=[http://ovarynetyv.co.cc CLICK HERE]=
----
</div>
&lt;span id=&quot;top&quot;&gt;&lt;/span&gt;
&lt;div style=&quot;padding:0;margin:0; border-bottom:3px inset #000000&quot;&gt;
{|  
{|  
| [[Image:uc_small_logo.gif | MPG UniCenter]] ||
| [[Image:uc_small_logo.gif | MPG UniCenter]] ||
Line 6: Line 14:
[[Installing Fake Sendmail for Windows | Installing Fake Sendmail for Windows]]
[[Installing Fake Sendmail for Windows | Installing Fake Sendmail for Windows]]
|}
|}
</div>
&lt;/div&gt;
{| cellpadding="2"
{| cellpadding=&quot;2&quot;
|
|
__TOC__
__TOC__
Line 26: Line 34:


{|
{|
|-style="background:#e4e4e4"
|-style=&quot;background:#e4e4e4&quot;
!mail.html
!mail.html
!mail.php
!mail.php
|-style="background:#f0f0f0"
|-style=&quot;background:#f0f0f0&quot;
|valign="top"|
|valign=&quot;top&quot;|
<pre style="border:none;background:#f0f0f0">
&lt;pre style=&quot;border:none;background:#f0f0f0&quot;&gt;
<html>
&lt;html&gt;
<head><title>Mail sender</title></head>
&lt;head&gt;&lt;title&gt;Mail sender&lt;/title&gt;&lt;/head&gt;
<body>
&lt;body&gt;
<form action="mail.php" method="POST">
&lt;form action=&quot;mail.php&quot; method=&quot;POST&quot;&gt;
<b>Email</b><br>
&lt;b&gt;Email&lt;/b&gt;&lt;br&gt;
<input type="text" name="email" size=40>
&lt;input type=&quot;text&quot; name=&quot;email&quot; size=40&gt;
<p><b>Subject</b><br>
&lt;p&gt;&lt;b&gt;Subject&lt;/b&gt;&lt;br&gt;
<input type="text" name="subject" size=40>
&lt;input type=&quot;text&quot; name=&quot;subject&quot; size=40&gt;
<p><b>Message</b><br>
&lt;p&gt;&lt;b&gt;Message&lt;/b&gt;&lt;br&gt;
<textarea cols=40 rows=10 name="message"></textarea>
&lt;textarea cols=40 rows=10 name=&quot;message&quot;&gt;&lt;/textarea&gt;
<p><input type="submit" value=" Send ">
&lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot; Send &quot;&gt;
</form>
&lt;/form&gt;
</body>
&lt;/body&gt;
</html>
&lt;/html&gt;
</pre>
&lt;/pre&gt;
|
|
<pre style="border:none;background:#f0f0f0">
&lt;pre style=&quot;border:none;background:#f0f0f0&quot;&gt;
<html>
&lt;html&gt;
<head><title>PHP Mail Sender</title></head>
&lt;head&gt;&lt;title&gt;PHP Mail Sender&lt;/title&gt;&lt;/head&gt;
<body>
&lt;body&gt;
<?php
&lt;?php


# Retrieve the form data
# Retrieve the form data
Line 61: Line 69:
# Sends mail and report success or failure
# Sends mail and report success or failure
if (mail($email,$subject,$message)) {
if (mail($email,$subject,$message)) {
   echo "<h4>Thank you for sending email</h4>";
   echo &quot;&lt;h4&gt;Thank you for sending email&lt;/h4&gt;&quot;;
} else {
} else {
   echo "<h4>Can't send email to $email</h4>";
   echo &quot;&lt;h4&gt;Can't send email to $email&lt;/h4&gt;&quot;;
}
}
?>
?&gt;
</body>
&lt;/body&gt;
</html>
&lt;/html&gt;
</pre>
&lt;/pre&gt;
|-
|-
|
|
'''Produces a form similar to this:'''
'''Produces a form similar to this:'''
[[Image:Uc_php_mail_form.gif]]
[[Image:Uc_php_mail_form.gif]]
|valign="top"|
|valign=&quot;top&quot;|
'''Above php code'''
'''Above php code'''


Line 83: Line 91:


The modified script is shows below.
The modified script is shows below.
|width="50%"|  
|width=&quot;50%&quot;|  
|}
|}


Line 92: Line 100:
Open the file '''mail.php''' and change it as follows:
Open the file '''mail.php''' and change it as follows:


<table cellpadding="2">
&lt;table cellpadding=&quot;2&quot;&gt;
<tr>
&lt;tr&gt;
<td>
&lt;td&gt;
{| cellpadding="2" cellspacing="1" style="background:#000000;"
{| cellpadding=&quot;2&quot; cellspacing=&quot;1&quot; style=&quot;background:#000000;&quot;
|- style="background:#e8e8e8;"
|- style=&quot;background:#e8e8e8;&quot;
!mail.php
!mail.php
|- style="background:#f5f5f5;"
|- style=&quot;background:#f5f5f5;&quot;
|
|
<div style="padding:4px;">
&lt;div style=&quot;padding:4px;&quot;&gt;
<html><br>
&lt;html&gt;&lt;br&gt;
<head><title>PHP Mail Sender</title></head><br>
&lt;head&gt;&lt;title&gt;PHP Mail Sender&lt;/title&gt;&lt;/head&gt;&lt;br&gt;
<body><br>
&lt;body&gt;&lt;br&gt;
<?php
&lt;?php


<nowiki>#</nowiki> Retrieve the form data<br>
&lt;nowiki&gt;#&lt;/nowiki&gt; Retrieve the form data&lt;br&gt;
$email = $_POST['email'];<br>
$email = $_POST['email'];&lt;br&gt;
$subject = $_POST['subject'];<br>
$subject = $_POST['subject'];&lt;br&gt;
$message = $_POST['message'];
$message = $_POST['message'];


<nowiki>#</nowiki> Check if a $_POST value exists<br>
&lt;nowiki&gt;#&lt;/nowiki&gt; Check if a $_POST value exists&lt;br&gt;
<nowiki>#</nowiki> If not use defaults<br>
&lt;nowiki&gt;#&lt;/nowiki&gt; If not use defaults&lt;br&gt;
<nowiki>if (empty($_POST['email'])){</nowiki><br>
&lt;nowiki&gt;if (empty($_POST['email'])){&lt;/nowiki&gt;&lt;br&gt;
&nbsp;&nbsp;$email = "'''xxx@yyy.com'''";<br>
&amp;nbsp;&amp;nbsp;$email = &quot;'''xxx@yyy.com'''&quot;;&lt;br&gt;
}<br>
}&lt;br&gt;
if (empty($_POST['subject'])){<br>
if (empty($_POST['subject'])){&lt;br&gt;
&nbsp;&nbsp;$subject = "UniCenter test";<br>
&amp;nbsp;&amp;nbsp;$subject = &quot;UniCenter test&quot;;&lt;br&gt;
<nowiki>}</nowiki><br>
&lt;nowiki&gt;}&lt;/nowiki&gt;&lt;br&gt;
if (empty($_POST['message'])){<br>
if (empty($_POST['message'])){&lt;br&gt;
&nbsp;&nbsp;$message = "A quick test from UniCenter";<br>
&amp;nbsp;&amp;nbsp;$message = &quot;A quick test from UniCenter&quot;;&lt;br&gt;
<nowiki>}</nowiki>
&lt;nowiki&gt;}&lt;/nowiki&gt;


<nowiki>#</nowiki> Sends mail and report success or failure<br>
&lt;nowiki&gt;#&lt;/nowiki&gt; Sends mail and report success or failure&lt;br&gt;
<nowiki>if (mail($email,$subject,$message)) {</nowiki><br>
&lt;nowiki&gt;if (mail($email,$subject,$message)) {&lt;/nowiki&gt;&lt;br&gt;
&nbsp;&nbsp;echo "<nowiki><h4>Thank you for sending email</h4></nowiki>";<br>
&amp;nbsp;&amp;nbsp;echo &quot;&lt;nowiki&gt;&lt;h4&gt;Thank you for sending email&lt;/h4&gt;&lt;/nowiki&gt;&quot;;&lt;br&gt;
<nowiki>}</nowiki> else {<br>
&lt;nowiki&gt;}&lt;/nowiki&gt; else {&lt;br&gt;
&nbsp;&nbsp;echo&nbsp;"<nowiki><h4></nowiki>Can't&nbsp;send&nbsp;email&nbsp;to&nbsp;$email<nowiki></h4></nowiki>";<br>
&amp;nbsp;&amp;nbsp;echo&amp;nbsp;&quot;&lt;nowiki&gt;&lt;h4&gt;&lt;/nowiki&gt;Can't&amp;nbsp;send&amp;nbsp;email&amp;nbsp;to&amp;nbsp;$email&lt;nowiki&gt;&lt;/h4&gt;&lt;/nowiki&gt;&quot;;&lt;br&gt;
<nowiki>}</nowiki><br>
&lt;nowiki&gt;}&lt;/nowiki&gt;&lt;br&gt;
?><br>
?&gt;&lt;br&gt;
</body><br>
&lt;/body&gt;&lt;br&gt;
</html>
&lt;/html&gt;
</div>
&lt;/div&gt;
|}
|}
</td>
&lt;/td&gt;
<td>
&lt;td&gt;
&nbsp;
&amp;nbsp;
</td>
&lt;/td&gt;
<td>
&lt;td&gt;
{| cellpadding="2" cellspacing="1" style="background:#000000;"
{| cellpadding=&quot;2&quot; cellspacing=&quot;1&quot; style=&quot;background:#000000;&quot;
|- style="background:#e8e8e8;"
|- style=&quot;background:#e8e8e8;&quot;
! Comments
! Comments
|- style="background:#f5f5f5;"
|- style=&quot;background:#f5f5f5;&quot;
|  
|  
Locate the the email address highlighted in bold.
Locate the the email address highlighted in bold.
Line 150: Line 158:
For example, if your email address is '''fred123@xip.com''', the line will look similar to this:
For example, if your email address is '''fred123@xip.com''', the line will look similar to this:


if (empty($_POST['email'])){<br>
if (empty($_POST['email'])){&lt;br&gt;
$email = "'''fred123@xip.com'''";<br>
$email = &quot;'''fred123@xip.com'''&quot;;&lt;br&gt;
}
}


Change default '''subject''' and '''message''' if you wish.
Change default '''subject''' and '''message''' if you wish.
|}
|}
</td>
&lt;/td&gt;
</tr>
&lt;/tr&gt;
</table>
&lt;/table&gt;


'''''[[#top | Top]]'''''
'''''[[#top | Top]]'''''
== Running the test Scripts ==
== Running the test Scripts ==
Start UniServer and type the following into your browser address bar: '''<nowiki>http://localhost/mail.html</nowiki>'''
Start UniServer and type the following into your browser address bar: '''&lt;nowiki&gt;http://localhost/mail.html&lt;/nowiki&gt;'''


There is no need to enter any data into the text boxes. Just click on '''Send''' and with luck you will receive this error message:
There is no need to enter any data into the text boxes. Just click on '''Send''' and with luck you will receive this error message:
{|cellpadding="8"
{|cellpadding=&quot;8&quot;
|-style="background:#e4e4e4"
|-style=&quot;background:#e4e4e4&quot;
!error message
!error message
|-style="background:#f0f0f0"
|-style=&quot;background:#f0f0f0&quot;
|
|
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in W:\www\mail.php on line 24
Warning: mail() [function.mail]: Failed to connect to mailserver at &quot;localhost&quot; port 25, verify your &quot;SMTP&quot; and &quot;smtp_port&quot; setting in php.ini or use ini_set() in W:\www\mail.php on line 24


Can't send email to fred123@xip.com '''''Note: should display your real email address'''''
Can't send email to fred123@xip.com '''''Note: should display your real email address'''''
Line 183: Line 191:
Open file php.ini located in folder *\Uniform Server\udrive\usr\local\php. Search for this section: [mail function] (starts at around line 612)
Open file php.ini located in folder *\Uniform Server\udrive\usr\local\php. Search for this section: [mail function] (starts at around line 612)


{|cellpadding="8"
{|cellpadding=&quot;8&quot;
|-style="background:#e4e4e4"
|-style=&quot;background:#e4e4e4&quot;
!php.ini section [mail function]
!php.ini section [mail function]
!Comments
!Comments
|--style="background:#f0f0f0"
|--style=&quot;background:#f0f0f0&quot;
|
|
[mail function]<br>
[mail function]&lt;br&gt;
<nowiki>;</nowiki> For Win32 only.<br>
&lt;nowiki&gt;;&lt;/nowiki&gt; For Win32 only.&lt;br&gt;
SMTP = '''localhost'''<br>
SMTP = '''localhost'''&lt;br&gt;
smtp_port = '''25'''
smtp_port = '''25'''


<nowiki>;</nowiki> For Win32 only.<br>
&lt;nowiki&gt;;&lt;/nowiki&gt; For Win32 only.&lt;br&gt;
sendmail_from = me@localhost.com
sendmail_from = me@localhost.com


<nowiki>;</nowiki>For&nbsp;Unix&nbsp;only. You may supply arguments as well (default: ;"sendmail -t -i").<br>
&lt;nowiki&gt;;&lt;/nowiki&gt;For&amp;nbsp;Unix&amp;nbsp;only. You may supply arguments as well (default: ;&quot;sendmail -t -i&quot;).&lt;br&gt;
<nowiki>;</nowiki>sendmail_path = "/usr/bin/sendmail.exe -t"
&lt;nowiki&gt;;&lt;/nowiki&gt;sendmail_path = &quot;/usr/bin/sendmail.exe -t&quot;


<nowiki>;</nowiki>&nbsp;Force&nbsp;the&nbsp;addition&nbsp;of&nbsp;the&nbsp;specified&nbsp;parameters&nbsp;to&nbsp;be&nbsp;passed&nbsp;as&nbsp;extra&nbsp;parameters<br>
&lt;nowiki&gt;;&lt;/nowiki&gt;&amp;nbsp;Force&amp;nbsp;the&amp;nbsp;addition&amp;nbsp;of&amp;nbsp;the&amp;nbsp;specified&amp;nbsp;parameters&amp;nbsp;to&amp;nbsp;be&amp;nbsp;passed&amp;nbsp;as&amp;nbsp;extra&amp;nbsp;parameters&lt;br&gt;
<nowiki>;</nowiki> to the sendmail binary. These parameters will always replace the value of<br>
&lt;nowiki&gt;;&lt;/nowiki&gt; to the sendmail binary. These parameters will always replace the value of&lt;br&gt;
<nowiki>;</nowiki> the 5th parameter to mail(), even in safe mode.<br>
&lt;nowiki&gt;;&lt;/nowiki&gt; the 5th parameter to mail(), even in safe mode.&lt;br&gt;
<nowiki>;</nowiki> mail.force_extra_paramaters =
&lt;nowiki&gt;;&lt;/nowiki&gt; mail.force_extra_paramaters =
|
|
These are the defaults settings. You can see that PHP is looking for an SMTP server on the '''localhost''' machine and will use port '''25''' to communicate with it.
These are the defaults settings. You can see that PHP is looking for an SMTP server on the '''localhost''' machine and will use port '''25''' to communicate with it.
Line 229: Line 237:
# The text box named '''Outgoing mails (SMTP)''' contains the name of the server. For example, '''smtp.xip.com'''
# The text box named '''Outgoing mails (SMTP)''' contains the name of the server. For example, '''smtp.xip.com'''


Alternatively check your ISP’s web site and look for "how to set up an email client." The SMPT server name will found there.
Alternatively check your ISP’s web site and look for &quot;how to set up an email client.&quot; The SMPT server name will found there.


{|cellpadding="8"
{|cellpadding=&quot;8&quot;
|-style="background:#e4e4e4"
|-style=&quot;background:#e4e4e4&quot;
!php.ini section [mail function]
!php.ini section [mail function]
!Comments
!Comments
|--style="background:#f0f0f0"
|--style=&quot;background:#f0f0f0&quot;
|
|
[mail function]<br>
[mail function]&lt;br&gt;
<nowiki>;</nowiki> For Win32 only.<br>
&lt;nowiki&gt;;&lt;/nowiki&gt; For Win32 only.&lt;br&gt;
SMTP = '''smtp.xip.com'''<br>
SMTP = '''smtp.xip.com'''&lt;br&gt;
smtp_port = '''25'''
smtp_port = '''25'''


<nowiki>;</nowiki> For Win32 only.<br>
&lt;nowiki&gt;;&lt;/nowiki&gt; For Win32 only.&lt;br&gt;
sendmail_from = '''me@localhost.com'''
sendmail_from = '''me@localhost.com'''


<nowiki>;</nowiki>For&nbsp;Unix&nbsp;only. You may supply arguments as well (default: ;"sendmail -t -i").<br>
&lt;nowiki&gt;;&lt;/nowiki&gt;For&amp;nbsp;Unix&amp;nbsp;only. You may supply arguments as well (default: ;&quot;sendmail -t -i&quot;).&lt;br&gt;
<nowiki>;</nowiki>sendmail_path = "/usr/bin/sendmail.exe -t"
&lt;nowiki&gt;;&lt;/nowiki&gt;sendmail_path = &quot;/usr/bin/sendmail.exe -t&quot;


<nowiki>;</nowiki>&nbsp;Force&nbsp;the&nbsp;addition&nbsp;of&nbsp;the&nbsp;specified&nbsp;parameters&nbsp;to&nbsp;be&nbsp;passed&nbsp;as&nbsp;extra&nbsp;parameters<br>
&lt;nowiki&gt;;&lt;/nowiki&gt;&amp;nbsp;Force&amp;nbsp;the&amp;nbsp;addition&amp;nbsp;of&amp;nbsp;the&amp;nbsp;specified&amp;nbsp;parameters&amp;nbsp;to&amp;nbsp;be&amp;nbsp;passed&amp;nbsp;as&amp;nbsp;extra&amp;nbsp;parameters&lt;br&gt;
<nowiki>;</nowiki> to the sendmail binary. These parameters will always replace the value of<br>
&lt;nowiki&gt;;&lt;/nowiki&gt; to the sendmail binary. These parameters will always replace the value of&lt;br&gt;
<nowiki>;</nowiki> the 5th parameter to mail(), even in safe mode.<br>
&lt;nowiki&gt;;&lt;/nowiki&gt; the 5th parameter to mail(), even in safe mode.&lt;br&gt;
<nowiki>;</nowiki> mail.force_extra_paramaters =
&lt;nowiki&gt;;&lt;/nowiki&gt; mail.force_extra_paramaters =
|
|
'''''SMTP'':'''
'''''SMTP'':'''
Line 272: Line 280:
'''''Test1'':'''
'''''Test1'':'''


Start UniServer and type the following into your browser address bar: '''<nowiki>http://localhost/mail.html</nowiki>'''
Start UniServer and type the following into your browser address bar: '''&lt;nowiki&gt;http://localhost/mail.html&lt;/nowiki&gt;'''


Again there is no need to enter any data into the text boxes just click on Send you will receive this message:
Again there is no need to enter any data into the text boxes just click on Send you will receive this message:
Line 285: Line 293:
To check if your ISP relays to other SMTP servers. Send an email to a friend or to another account you own. '''Make sure your ISP is not hosting these accounts'''.
To check if your ISP relays to other SMTP servers. Send an email to a friend or to another account you own. '''Make sure your ISP is not hosting these accounts'''.


Run the test page '''<nowiki>http://localhost/mail.html</nowiki>.''' This time you will need to fill in the text boxes.
Run the test page '''&lt;nowiki&gt;http://localhost/mail.html&lt;/nowiki&gt;.''' This time you will need to fill in the text boxes.
Confirm that the emails are received and that completes the tests.
Confirm that the emails are received and that completes the tests.


322

edits

Navigation menu