The following is a simple script to use php sendmail function. This is only for testing purposes. This script works on a server but it does not work on the server that I currently host for my site.
If I just use mail("name@myemail.com", "My Subject", "Line 1\nLine 2\nLine 3"); , it works but when it comes to forms, it don't work on this server. Can anyone tell me how to solve this?
Script at Server that do not work
http://www.singalore.com/phpnuke/php/sendmail4.php
Script Server that works
http://www.htgk.com.sg/mc/php/sendmail4.php
The scripts are exactly the same on this 2 servers but results are different.
<?
if($action == "send_mail") {
$recipient = 'adjia@yahoo.com';
$subject = "Just a test from $name";
$body_of_email = "
This is the contents of the email from Name: $name
Who's email is: $email
and who's URL is: $url
";
$additional_headers = "From: $email\n";
if(mail($recipient, $subject, $body_of_email, $additional_headers)) {
print("mail successfully sent to $recipient");
} else {
print("oops! something didn't work right above, check the syntax of your code");
}
} else {
?>
<form METHOD=POST action="<? echo($PHP_SELF) ?>">
<input type="hidden" name="action" value="send_mail">
Name: <input type="text" name="name">
Your Email: <input type="text" name="email" size=40>
URL: <input type="text" name="url"> <input type="submit" value="Submit"></form>
<? } ?>