PHP Mailto Script Help Plz!

mattemme

New Member
Messages
1
Reaction score
0
Points
0
Hi Everyone!

I'm new to this site and am using it to help promote my new photography hobby. I'm trying desperately to implement a simple mailto form so that people can contact me without revealing my own email address. I'm having problems getting it to work though. Can anyone suggest/provide a script to use (as I'm not smart enough in these things to write one myself)? Or is it possible that it's x10's hosting that isn't allowing it to go through? I would appreciate any help possible.

Thanks so much
 

gameaddict2085

Member
Prime Account
Messages
111
Reaction score
1
Points
18
<?php
// This function checks for email injection. Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}

// Load form field data into variables.
$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['comments'] ;

// If the user tries to access this script directly, redirect them to feedback form,
if(!isset($_REQUEST['email_address'])) {
header( "Location: index.html" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($email_address) || empty($comments)) {
header( "Location: ErrorPage.html" );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($email_address) ) {
header( "Location: ErrorPage.html" );
}

// If we passed all previous tests, send the email!
else {

date_default_timezone_set('America/Los_Angeles');
//echo date('l jS \of F Y h:i:s A');
//echo " ... testing the mail() function " ;

$from = "youraccountname@yourdomain"; // MUST BE LEGIT ACCOUNT ON YOUR DOMAIN

$to="your@emailaddress.com" ; // CURRENTLY, not blocked by hotmail!

$mailbody= $email_address."
".$comments;
$subject="Site Email" ;

$headers = "Content-type: text/plain; charset=windows-1251 \r\n"; // MUST BE text/plain
$headers .= "From: $from\r\n";
$headers .= "Reply-To: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

$resp = mail($to, $subject, $mailbody, $headers);

if( $resp ){
header( "Location: ErrorPage.html" );
}else{
header( "Location: ErrorPage.html" );
}

?>

Edit the above to match your details and save as Email.php
Then add this form to your webpage:

<form method='post' action='Email.php'>
<input type='text' name='email_address' value='' />
<input type='text' name='comments' value='' />
</form>

I adapted this from someone else's work but I can't remember where I got it so all credit goes to somebody else :)
 
Last edited:

ellescuba27

Member
Messages
273
Reaction score
3
Points
18
Where's your submit button gameaddict2085?
Also, wouldn't it be better to use an SMTP Mailer like PHPMailer so Qmail doesn't open?
And yes, email can be sent through x10, but only with your cPanel email. You can't use x10 to connect to your personal mail.
 
Top