VAN_AL
asked on
PHP Mail - Not Working
Hi All,
I have a request form that is processed by PHP and sent to a specific user, the same code i've used on another site and works perfectly but on a different site (and server) it says mail sent by nothing arrives? I don't know why and need help figuring out why.
Code is attached.
I have a request form that is processed by PHP and sent to a specific user, the same code i've used on another site and works perfectly but on a different site (and server) it says mail sent by nothing arrives? I don't know why and need help figuring out why.
Code is attached.
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['first_name']) == '') {
$hasError = true;
} else {
$name = trim($_POST['first_name']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['last_name']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['last_name']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['phone']) == '') {
$hasError = true;
} else {
$phone = trim($_POST['phone']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['describe']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['describe']));
} else {
$comments = trim($_POST['describe']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'ashala@nextphasestrategy.com';
$body = "First Name: $name \n\nLast Name: $subject \n\nPhone: $phone \n\nEmail: $email \n\nComments:\n $comments";
$subject = "Adroit Resources Inc: Registration for Investors Updates";
$headers = 'From: Adroit Resources Inc<'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<!-- include jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script src="../Scripts/jquery.validate.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#contactform").validate();
});
</script>
</head>
<body>
<div>
<p><h1>Register for Investor Updates</h1></p>
<?php if(isset($hasError)) { //If errors are found ?>
<p class="error">Please check if you've filled all the fields with valid information. Thank you.</p>
<?php } ?>
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<p><strong>Email Successfully Sent!</strong></p>
<p>Thank you <strong><?php echo $name;?></strong> for registering to receive Adroit Resources Inc Investor Updates! Your email was successfully sent and you will be added to our mailing list.</p>
<?php } ?>
<p>
<form method="post" class="cmxform" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform">
<fieldset>
<label class="field-first">First Name *<input type="text" name="first_name" id="first_name" class="required" value="" /></label>
<label class="field-last">Last Name *<input type="text" name="last_name" id="last_name" class="required" value="" /></label>
<label class="field-phone">Phone *<input type="text" name="phone" id="phone" class="required" value="" /></label>
<label class="field-email">Email *<input type="text" name="email" id="email" class="required email" value="" /></label>
</fieldset>
<fieldset>
<label class="field-describe">Comments<br /><textarea name="describe" id="describe" cols="40" rows="5"></textarea></label>
</fieldset>
<fieldset>
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="submitted" value="TRUE" />
</fieldset>
</form>
</p>
</div>
</body>
</html>
If the same code works on a different server, the problem is probably in the settings you're using to access the mail server, or the mail server configuration itself. For example your current server might require SMTP authentication. Can you successfully send an email from the PHP server using a mail client?
Or there may not be an active mailserver on that machine. Is it Windows or Linux?
ASKER
It's a w3 server (i don't know what this is exactly) and i am able to send email with the above code from serveral servers... i tried the code below and it works on all servers except this one, it's on a private server for a client talked to the it tech guys says to use auth_smtp?
<?php
$to = "me@0000.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
$worked = mail($to,$subject,$message ,$headers) ;
if($worked) {
echo "Mail Sent.";
} else {
echo "Mail Not Sent.";
}
?>
<?php
$to = "me@0000.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
$worked = mail($to,$subject,$message
if($worked) {
echo "Mail Sent.";
} else {
echo "Mail Not Sent.";
}
?>
ASKER
Oh it's a Linux server, sorry i forgot to run phpinfo on it, which setting in phpinfo would indicate that perhaps the admin might have disabled the mail() function (I'm guessing that's the issue here)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No he says the he usually uses auth_smtp through a regular mail server. I don't know what that means?
ASKER
What feature would be disabled would it show up on the php info display and what would that be?
I think mail is a built-in feature. You might look in the PHP core of phpinfo() to see.
Try running this script and let's see what happens. Post back here when you have run it
Try running this script and let's see what happens. Post back here when you have run it
<?php
error_reporting(E_ALL);
mail('Ray.Paseur@Gmail.com', 'EE Q_26853903', 'Testing 123');
ASKER
I get a blank page, i tried removing the mail function and run it with error_reporting on but still got a blank page.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Ray_Paseur I ran you script as you posted and came back with no errors (blank page) and i re-ran your script with my email in the mail function and came up with the same result.
Also one stupid question sorry, what username & password (see code below) goes in here if I am trying to create a form for others fill out and have the email sent to specific email addresse?
// Define SMTP Parameters
$params['host'] = 'mail.authsmtp.com';
$params['port'] = '25';
$params['auth'] = 'PLAIN';
$params['username'] = 'USERNAME'; //CHANGE
$params['password'] = 'PASSWORD'; //CHANGE
Also one stupid question sorry, what username & password (see code below) goes in here if I am trying to create a form for others fill out and have the email sent to specific email addresse?
// Define SMTP Parameters
$params['host'] = 'mail.authsmtp.com';
$params['port'] = '25';
$params['auth'] = 'PLAIN';
$params['username'] = 'USERNAME'; //CHANGE
$params['password'] = 'PASSWORD'; //CHANGE
Hmm... No email arrived at all.
I think you would want to create an email account on a mail server (GMail is free) and use the username and password associated with that SMTP server.
If you are letting others use your site to send email to some 3rd party address, you will want to learn about the principles of "Accept Only Known Good Values" to avoid becoming an open relay for spam.
I think you would want to create an email account on a mail server (GMail is free) and use the username and password associated with that SMTP server.
If you are letting others use your site to send email to some 3rd party address, you will want to learn about the principles of "Accept Only Known Good Values" to avoid becoming an open relay for spam.
ASKER
No emails arrived at all, I don't know what's going on?
Admin says he turned on relaying for our ip address and it should all work now but it doesn't.
Admin says he turned on relaying for our ip address and it should all work now but it doesn't.
May need to restart the server - some of these things are cached.
For what it's worth, several hosting companies require you to send from a valid email address on your account or at least on their servers. Godaddy recently changed to that policy and one of my accounts stopped receiving email from their forms. I had to create an email address for that account so that the form on the web site could be emailed to the owner from a valid email address.
ASKER
I'm dealing wth an overprotective admin and have to wait until he's go and ready to restart it (if he does), what should have been a simple email form turned into a long thread with possible solutions, also I am not 100% sure but it looks like PEAR isn't installed on the server either so the previously suggested solution from Dave wouldn't work either..
Mail requires that sendmail is installed on the server. Check out phpmailer for a super easy solution that uses any smtp server.
Hai,
"PHPMAILER" is the best one to process the mailing events
1) Can send bulk mails
2) Can have bulk attachment
3) Can avoid spams
4) Any type of mail id's will be accepted to the mailer class
"PHPMAILER" is the best one to process the mailing events
1) Can send bulk mails
2) Can have bulk attachment
3) Can avoid spams
4) Any type of mail id's will be accepted to the mailer class
Go back to the link at ID:35003215 above and install that script. I've done it before and you have to follow the instructions carefully, but it works and it will get you "over the hump." Best of luck with it, ~Ray
ASKER
Thanks will give a try.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help all, problem solved.