Jump to content

PHP mail script - My server won't let me...


geektasic

Recommended Posts

Hello!

 

Nice you meet you! I'm new :)

 

I'm installing a Flash & PHP mail form on my website. The problem is; my host (Fasthosts) requires me to add or edit additional code for any third party scripts to work.

 

Here are their instructions:

 

To prevent spam being sent through our web servers, there are certain conditions that must be met before our SMTP servers will send the email.

 

1) Email must be sent to, or from, an email address hosted by Fasthosts. An email address hosted by Fasthosts is not the same as a domain name hosted by Fasthosts. If your domain's MX record points to another email provider, it will not count as being hosted by Fasthosts.

 

2) To stop misuse of your form by third parties the sendmail_from variable should be set to your Fasthosts hosted email address. While access to the php.ini file is restricted on our shared environment, you can sent this variable using the ini_set() command, shown below.

 

3) A fifth parameter -f should be added to the sendmail function. This will set the name of the from email address.

In its basic form, a simple sendmail script will look like this:

<?php

ini_set("sendmail_from", " [email protected] ");

mail($email_to, $email_subject, $email_message, $headers, '-f'[email protected]);

?>

 

Provided that you set the sendmail variable, before attempting to send the email. Specify the from address as a fifth parameter in the sendmail function, and the email is either to, or from, a Fasthosts hosted email address you should have no problems.

 

And here is the PHP for my mail script

 

<?php

 

// read the variables form the string, (this is not needed with some servers).

$subject = $_REQUEST["subject"];

$message = $_REQUEST["message"];

$sender = $_REQUEST["sender"];

 

 

// include sender IP in the message.

$full_message = $_SERVER['REMOTE_ADDR'] . "\n\n" . $message;

$message= $full_message;

 

// remove the backslashes that normally appears when entering " or '

$message = stripslashes($message);

$subject = stripslashes($subject);

$sender = stripslashes($sender);

 

// add a prefix in the subject line so that you know the email was sent by online form

$subject = "Contact form ". $subject;

 

// send the email, make sure you replace [email protected] with your email address

if(isset($message) and isset($subject) and isset($sender)){

mail("[email protected]", $subject, $message, "From: $sender");

}

?>

 

Can anyone help me make the mail script work on Fasthosts? I really don't know where to put what with the instructions they have provided.

 

Thank you for your patience! I'm all new to PHP :)

 

Geektastic

Link to comment
https://forums.phpfreaks.com/topic/122426-php-mail-script-my-server-wont-let-me/
Share on other sites

  • 2 weeks later...

as far as i can tell, the following mods in bold to your script should make it work:

also, the stuff i made an assumption: $_REQUEST["sender"] = the email address of the person sending the email

 

in red = your email address, which as stated by their instructions must be hosted with them.... so check your MX servers or if you dont know how to do that contact them...

 

ALSO, you get the order of params in the mail() function mixed up! :)http://www.php.net/function.mail

 

the first param should be $sender (assuming my above assumption is correct) and also, you forgot to specify the additional "-f..." parameter they requested

 


<?php

// read the variables form the string, (this is not needed with some servers).
$subject = $_REQUEST["subject"];
$message = $_REQUEST["message"];
$sender = $_REQUEST["sender"];


// include sender IP in the message.
$full_message = $_SERVER['REMOTE_ADDR'] . "\n\n" . $message;
$message= $full_message;

// remove the backslashes that normally appears when entering " or '
$message = stripslashes($message);
$subject = stripslashes($subject);
$sender = stripslashes($sender);

// add a prefix in the subject line so that you know the email was sent by online form
$subject = "Contact form ". $subject;

// send the email, make sure you replace [email protected] with your email address
[b]ini_set("sendmail_from", " [color=red][email protected][/color]");[\b]
[b]if(isset($message, $subject, $sender)){[/b] /* just a hint, you can pass multiple variables to a single isset() function call [url]http://www.php.net/isset[/url] */
   [b]mail($sender, $subject, $message, "From: [color=red][email protected][/color], '-f'[color=red][email protected][/color]");[/b]
}
?>

 

 

try my code, (and string the and tags!!) and if it still doesnt work contact tech support)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.