 |
ross96 Level: Protégé
 Registered: 01-09-2005 Posts: 8
|
send mail with PHP
How can I sand an email from a PHP script? ...I need to send a mail when users compile a form and then send it
|
|
15-11-2005 at 10:10 AM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 16
|
Re: send mail with PHP
Something like this (this script works at my webhost):
<?
// Places have said to fill in the below items...
// however, when I did, the name in all the fields below were doubled
// (ie: me@mydomain.com;me@mydomain.com) when received.
$_toEmailAddress = "";
$_ccEmailAddress = "";
$_bccEmailAddress = "";
$_subject = $_POST[ "subject" ];
$_from = $email;
$message = "Message<br />";
$_headers = "";
$_headers .= "MIME-Version: 1.0\r\n";
$_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$_headers .= "From: " . $email . "\r\n";
$_headers .= "To: whoever@adomain.com\r\n";
$_headers .= "CC: ". $email ."\r\n";
$_headers .= "Reply-To: " . $email ."\r\n";
$_headers .= "X-Priority: 0\r\n";
$_headers .= "X-MSMail-Priority: Normal\r\n";
$_headers .= "X-Mailer: name_of_mailer_anything_i_think";
$mailresponse = mail("$_toEmailAddress", "$_subject", "$message", $_headers);
?>
|
[Edited by admin on 31-01-2006 at 08:17 AM GMT]
____________________________
Everywhere's Local (pre-release), My company's website
|
|
16-11-2005 at 04:10 AM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 16
|
Re: send mail with PHP
Just in the php file... or in a file by itself, and called as in a function.
____________________________
Everywhere's Local (pre-release), My company's website
|
|
04-01-2006 at 07:56 AM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 16
|
Re: send mail with PHP
As far as how many pages, it could be one, two, or a hundred fifty. It all depends on how you gather information, or display the information.
It all depends on how you're using the code to send a message. It's "less complex" in a way if it's 2 pages, one to collect the data, the other to send the mail, but it all depends on what you're wanting...
Something like:
<html>
<head>
<title>Send E-Mail Test</title>
</head>
<body>
<?php
if ( isset( $_POST['name'] ) )
$name = $_POST['name'];
if ( isset( $_POST['email'] ) )
$toemail = $_POST['email'];
if ( isset( $_POST['type'] ) )
$subject = $_POST['type'];
if ( isset( $_POST['message'] ) )
$message = $_POST['message'];
if ( $name != '' && $email != '' ) // and any other required fields
{
$fromemail = "the_from_email";
// Now... you either include the code I supplied in the following file
// wrapped in a function with the parameters as show in the calling function
// name doesn't have to be the same as the file, it just happens to be here
include ( 'mailit.php' );
mailit( $toemail, $fromemail, $subject, $message);
// Or you do it similar without a file
$_toEmailAddress = "";
$_ccEmailAddress = "";
$_bccEmailAddress = "";
$_subject = $subject;
$_from = $fromemail;
$message = "Info from webform:<br />" . $message;
$_headers = "";
$_headers .= "MIME-Version: 1.0\r\n";
$_headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$_headers .= "From: $fromemail\r\n";
$_headers .= "To: $toemail\r\n";
$_headers .= "CC: $fromemail\r\n";
$_headers .= "Reply-To: $fromemail\r\n";
$_headers .= "X-Priority: 0\r\n";
$_headers .= "X-MSMail-Priority: Normal\r\n";
$_headers .= "X-Mailer: name_of_mailer_anything_i_think";
$mailresponse = mail("$_toEmailAddress", "$_subject", "$message", $_headers);
echo "<p style=\"font-size:larger;\">Thank you for your comments</p>\n";
}
else
{
// Display any message to the user about required fields
// although check to make sure they don't see it before they submit
// the form (i.e. no warning of "missing name!" if they never had the chance
// to enter a name)
?>
<form action="contactus.phtml" method="post">
<div style="padding:5px;">
<p>
Your name:
<input type="text" name="name" size="50" value="" />
</p>
<p>
Your e-mail address:
<span style="font-size:x-small;">(for a copy of this message & a reply)</span>
<br />
<input type="text" name="email" size="35" value="" />
</p>
<p>
Message is about:
<select name="type">
<option value="account">Account issues</option>
<option value="report">Reporting a post</option>
<option value="web">Website issue</option>
<option value="advertising">Advertising</option>
</select>
</p>
<p>
Message: <br />
<textarea name="message" cols="50" rows="6"></textarea>
</p>
<p>
<input type="submit" name="submit" value="Send Message" />
</p>
</div>
</form>
<?
}//end of no data or required fields missing
?>
</body>
</html>
|
____________________________
Everywhere's Local (pre-release), My company's website
|
|
31-01-2006 at 11:25 PM |
|
|
|
|
 |
 |