You are here: sending email to address entered in field « All PHP « IT news, forums, messages
sending email to address entered in field

Posted by NewbieSupreme on 06/07/06 23:56

For some reason I can't send emails to addresses in a form field unless the
email address is on the SMTP server as the sending SMTP is (ie. if the form
is hosted at MyServer.com, and the SMTP is declared as mail.myserver.com, I
can only send emails to @MyServer.com addresses).

Can anyone help me figure out how to send emails to addresses entered in a
form field, and make sure they get to things like Yahoo, Hotmail addresses,
etc.?

I'm on a Windows server and I have tried using the following 2 scripts:

<?


$mailto = trim(htmlentities($_POST['EMail']));

$formurl = "http://www.MyServer.com/Enter.htm" ;
$errorurl = "http://www.MyServer.com/error.htm" ;
$thankyouurl = "http://www.MyServer.com/Thanks2.htm" ;

$uself = 1;

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\n" : "\n" ;
$Addy = $_POST['Addy'] ;
$Zip = $_POST['Zip'] ;
$Email = $_POST['Email'] ;
$EmailRet = 'ReturnAddress@MyServer.com' ;
$Name = 'Me' ;
$subject = "Directions to Event" ;
$AddressW = str_replace(" ", "+", $Addy) ;
$http_referrer = getenv( "HTTP_REFERER" );

if(getenv("HTTP_X_FORWARDED_FOR")){
$ip=getenv("HTTP_X_FORWARDED_FOR");
}
else{
$ip=getenv("REMOTE_ADDR");
}

if (!isset($_POST['Email'])) {
header( "Location: $formurl" );
exit ;
}
//if (empty($FirstName) || empty($email) || empty($comments)) {
// header( "Location: $errorurl" );
// exit ;
//}
if ( ereg( "[\n]", $Addy ) || ereg( "[\n]", $Email ) ) {
header( "Location: $errorurl" );
exit ;
}

//if (get_magic_quotes_gpc()) {
// $Comments = stripslashes( $Comments );
//}

$messageproper =

//"This message was sent from:\n" .
//"$http_referrer\n" .

"\n\n------------------------------------------------------------\n\n" .


"Click the link below to open MapQuest directions from your point of
departure to the Event: \n\n" .
"
http://www.mapquest.com/directions/main.adp?go=1&do=nw&rmm=1&un=m&cl=EN&ct=NA&rsres=1&1ffi=&1l=&1g=&1pl=&1v=&1n=&2ffi=&2l=&2g=&2pl=&2v=&2n=&1pn=&1a=$AddressW&1c=&1s=&1z=$Zip&2pn=&2a=1299+Kafe+Stems+Street&2c=&2s=&2z=49102\n" ;




ini_set ("SMTP", "mail.MyServer.com");

mail($mailto, $subject, $messageproper,
"From: \"$Name\" <$EmailRet>" . $headersep . "Reply-To: \"$Name\"
<$EmailRet>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
//$Email = rawurlencode($Email);
//header( "Location: $thankyouurl?Email=$Email" );
exit ;

?>

- - - - - -

And this one which I found on a newsgroup, and works from wherever it's
hosted, but only sends to MyServer addresses when I put it on my server:


<?php

/*
* MailTest: Sends a short mail to a desired address
*/

// Report all errors that might occur
error_reporting(E_ALL);

// This variable will contain a message print out after calling mail()
$OutputResult = "";

// if the form has been sent
if (0 < count($_POST))
{
// Check if an email-address has been entered
if (true == isset($_POST['fldAddress']))
{
// Read the desired email-address
$addresser_email_to = trim(htmlentities($_POST['fldAddress']));

// Create the mail header
$mailheader = "From: Absender_Name <admin@MyServer.com>\n" .
"Content-Type: text/plain; charset=ISO-8859-1;";

// No comes the big question: In my account, mail() returns true,
// the mail however never reaches the desired address
ini_set ("SMTP", "mail.MyServer.com");
$mail = mail($addresser_email_to,
"Test of php-mail" ,
"Just a little test to see if php-mail works",
$mailheader);
// Check if mailing was successful
if ($mail == false)
{
$OutputResult = "Mail could not be send to
$addresser_email_to.<br>\n";
}
else
{
$OutputResult = "Mail send successfully to
$addresser_email_to.<br>\n";
}
}
}

// Print a little form to enter the mail address
echo "<html>\n" .
"\n" .
"<head>\n" .
" <TITLE>Mailtest</TITLE>\n" .
"</head>\n" .
"\n" .
"<body>\n";

if ("" != $OutputResult)
{
echo "<br>$OutputResult<br>\n";
}

echo " <form method=\"POST\" action=\"\">\n" .
" Address: <input name=\"fldAddress\" value=\"\">\n" .
" <input type=\"submit\" value=\"send\">\n" .
" </form>\n" .
"</body>\n" .
"\n" .
"</html>\n";
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация