Forum Moderators: coopster

Message Too Old, No Replies

mail() function question

         

slidernmfdco2

11:16 pm on Mar 27, 2005 (gmt 0)

10+ Year Member



I have moved my clients to a brand new server, which I am now maintaining, instead of going through a reseller.

Currently, here are my php.ini settings and a copy of the script that is currently running. I'm not great with php, but I can follow it and decipher it.

First, my php.ini settings.

[mail function]
;SMTP = localhost ;
;sendmail_from = me@localhost.com ;
sendmail_path = /usr/sbin/sendmail -t -i ;

Second, the code:

<?php
$error = 0;

if (($Name == "") ¦¦($Email == "" )¦¦ ($Comments == ""))
{
$error = 1;
}
if ($error == 1)
{
$l = "Location: [example.com...]
$l .="&Name=$Name&Email=$Email&Comments=$Comments";
header($l);
exit;
}

$youremail="iam@home.com"; // This is the address that the information submitted will be sent to.
$emailsubject="Contact form info!"; // This will the email's subject
$from_who="$Email";
$pagetitle="Thank You!"; // Title to be displayed on the sent info page.

if (getenv(HTTP_CLIENT_IP)){
$user_ip=getenv(HTTP_CLIENT_IP);
} else {
$user_ip=getenv(REMOTE_ADDR);
}

// Read POST request params into global vars
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Comments = $_POST['Comments'];
$fileatt = $_POST['fileatt'];

$message="Senders Name:\n=================\n$Name\n\n";
$message.="Senders Email:\n=================\n$Email\n\n";
$message.="Senders Comments:\n=================\n$Comments";

// Obtain file upload vars
$fileatt = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];

$headers = "From: $Email";

if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";

// Base64 encode the file data
$data = chunk_split(base64_encode($data));

// Add file attachment to the message
$message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n";
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
//echo $message;

} else{
switch($HTTP_POST_FILES['userfile']['error']){
case 0: //no error; possible file attack!
echo "There was a problem with your upload.";
break;
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
echo "The file you are trying to upload is too big.";
break;
case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
echo "The file you are trying to upload is too big.";
break;
case 3: //uploaded file was only partially uploaded
echo "The file you are trying upload was only partially uploaded.";
break;
case 4: //no file was uploaded
echo "You must select an image for upload.";
break;
default: //a default error, just in case! :)
echo "There was a problem with your upload.";
break;
}
}
mail($youremail, $emailsubject, $message, $headers);
$comments = nl2br($comments);
?>

It is a cpanel\WHM server running on Fedora. I doublechecked to make sure that I am not on any blacklists as well.

What do I need to change?

[edited by: ergophobe at 12:24 am (utc) on Mar. 28, 2005]
[edit reason] URL exemplified as per site rules [/edit]

dreamcatcher

11:20 pm on Mar 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the problem exactly?

slidernmfdco2

11:31 pm on Mar 27, 2005 (gmt 0)

10+ Year Member



Yeah, I guess that would help. :)

It's not sending mail.

coopster

1:03 am on Mar 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld [webmasterworld.com], slidernmfdco2.

Have you tried just a simple send mail first? What, if any, error messages are you receiving? As dc stated, you'll probably need to provide a few more specifics.

slidernmfdco2

1:20 am on Mar 28, 2005 (gmt 0)

10+ Year Member



I'm really not a php programmer and am still learning a little bit about it. I'll have to give it try real quick and see if I get any errors.

The script is one of my clients and it used to work on the old server that we were on, but now it isn't. I don't know much of what changed between the two servers as I did not have access to the php.ini file or what type of "sendmail" module was being used.

I will see if I can throw together a simple mail() script and see if I get any errors.

slidernmfdco2

1:57 am on Mar 28, 2005 (gmt 0)

10+ Year Member



<?php
$to = "iam@home.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body))
{
echo("<p>Message sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
?>

I used the above code as a simple send mail script. It returned a Message Sent line on the page when I ran it and put my email address in it, but I never received the email.

dreamcatcher

10:11 am on Mar 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



btw, welcome to WebmasterWorld slidernmfdco2. :)

Using the mail() function in an if statement won`t make much difference as it will always return true. The function does not actually test to see if the mail has been sent.

Silly question, but have you checked to see if the messages aren`t getting filtered as spam?

Its a process of elimination I think. Is there any way you can test the script on another server? If that works, check to see what the PHP.ini settings are for that server.

Strange you aren`t receiving any errors.

dc

slidernmfdco2

4:40 pm on Mar 28, 2005 (gmt 0)

10+ Year Member



Unfortunately, my former host where I had a reseller account said for security reasons, he could not give me the php.ini settings he uses. I told him what I needed it for.

I can't do much from my office, but I give this a shot on the other server when I get home.

In the meantime, can anyone help me out with a basic way to test this from the command line? I've tried all sorts of different ones and I kept getting missing token errors.