Jump to content

Archived

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

Twentyoneth

email script

Recommended Posts

I have been trying to get an email script to work for awihle, and nothing I do will work. I have tried the scripts from php.net/mail, and they will not work for me.

[code]<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?> [/code]

Thats the code I use, and of course I changed it to my information. Any suggestions?

Share this post


Link to post
Share on other sites
This always works for me... Assuming you have posted the email_address from a form.


[code]
$email_address = $_POST['email_address'];
$subject = "Subject Here";
$message = "Message Here";
    
mail($email_address, $subject, $message, "From: Your Name<yourname@youraddress.com>\nX-Mailer: PHP/" . phpversion());
[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=348372:date=Feb 22 2006, 11:32 AM:name=Twentyoneth)--][div class=\'quotetop\']QUOTE(Twentyoneth @ Feb 22 2006, 11:32 AM) [snapback]348372[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Still no luck :S
[/quote]

Are you getting an error or is the mail just not sending? If it just isn't sending then it could be your php.ini setup.

Share this post


Link to post
Share on other sites
No I dont get any errors, my host has erros turned off, and I dont believe I can access the php.ini file...is there a work around?

Share this post


Link to post
Share on other sites
hmmmm.... *thinks* rite how bout u try running it locally on ur machine and then u'll know wht the errror's are.... or use error handling (althoug not sure if it will work coz u said they have blocked showing all errors )

anyway hope i helped !!

Share this post


Link to post
Share on other sites
[!--quoteo(post=348956:date=Feb 24 2006, 04:00 AM:name=Twentyoneth)--][div class=\'quotetop\']QUOTE(Twentyoneth @ Feb 24 2006, 04:00 AM) [snapback]348956[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I pasted that code in my php and still nothing.
[/quote]

....Any help? After all of this time I cant get it to work...

Share this post


Link to post
Share on other sites
Can you post the code you are currently using, exactly as it is? Can you tell us exactly what does happen, i.e. define "doesn't work" for us?

I assume that the script is saved as somename.[b]php[/b] and that it is running on a server equipped with a mail server, not running on your computer?

Share this post


Link to post
Share on other sites
[!--quoteo(post=349466:date=Feb 25 2006, 11:27 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ Feb 25 2006, 11:27 PM) [snapback]349466[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Can you post the code you are currently using, exactly as it is? Can you tell us exactly what does happen, i.e. define "doesn't work" for us?

I assume that the script is saved as somename.[b]php[/b] and that it is running on a server equipped with a mail server, not running on your computer?
[/quote]


email.php
[code]<form action="submit.php" method="POST">
<b>Email:</b><br>
<input type="text" name="email_address" /><br>
<b>Subject:</b><br>
<input type="text" name="subject" /><br>
<b>Message:</b><br>
<input type="text" name="message" /><br><br>
<input type="submit" value="Submit" />
</form>[/code]

submit.php
[code]<?php

$email_address = $_POST['email_address'];
$subject = "Subject Here";
$message = "Message Here";
    
mail($email_address, $subject, $message, "From: Your Name<......@hotmail.com>\nX-Mailer: PHP/" . phpversion());

?>
[/code]

What it does, when you click submit, it sends you to "submit.php" and loads nothing but my layout. I dont get any error messages, my host has disabled it.

Share this post


Link to post
Share on other sites
[!--quoteo(post=349469:date=Feb 25 2006, 10:45 PM:name=Twentyoneth)--][div class=\'quotetop\']QUOTE(Twentyoneth @ Feb 25 2006, 10:45 PM) [snapback]349469[/snapback][/div][div class=\'quotemain\'][!--quotec--]What it does, when you click submit, it sends you to "submit.php" and loads nothing but my layout. I dont get any error messages, my host has disabled it.[/quote]
But there isn't any layout stuff in the version of submit.php that you posted.

Try this:

#1 change your form action to point to submit2.php and save that code
#2 save exactly the code you posted above (as submit.php) as submit2.php but add the two error reporting lines from the post by hitman6003
#3 upload the revised form code and submit2.php to your server

Run the new version of the form script. If there are no errors, you should see a blank page. Check the email address you are sending this to, including the spam and/or junk folders (although using a POP3 email address usually works more reliably than a free webmail address). Let us know what happens.

Share this post


Link to post
Share on other sites
I didnt paste my whole layout in the submit.php nor the email.php, but they both contain the same exact layout, with different code for whats being done. I have tried sending it to gmail, hotmail, yahoo, and outlook express accounts, and I have checked them, and nothing. I have put the error message lines in the code, but I get a blank page, where the error would be.

Share this post


Link to post
Share on other sites
To enable error reporting when your host has turned if off use:
[code]<?php
// To have all errors reported, use
ini_set('error_reporting', E_ALL);
// To have none of the errors reported(excludes major ones), use
ini_set('error_reporting', E_NONE);
?>[/code]

You may have to use the fifth parameter to the mail() function to set the "Return-path:" header to include the domainname you're sending the mail from.
[code]<?php
$p5 = 'anyname@domainname.com';
mail($to,$subj,$msg,$headers,$p5);
?>[/code]
Many email systems will now reject email messages here the domain name in the "Return-path:" header does not match the domain name in the "From:" header.

Ken

Share this post


Link to post
Share on other sites
I tried that, it still didnt work. Is there a way to turn the mail function on if it is turned off in the .ini file, like the error messages?

Share this post


Link to post
Share on other sites
Can you change hosts? You shouldn't be having so many problems with sending email.

If you'd like, I'll send you my contact info via a PM and you send me your full scripts. I will put them on one of my domains, I will tell you the URL and you can try them there. If the email works, then it's your hosting service. If this is the case I would switch hosts.

Ken

Share this post


Link to post
Share on other sites
I cant afford to change hosts, but I think that they might have disabled it for mass emailing from websites, but Im just having my website email me.

Is it possible to do the "ini_set" thing for the mail function?

Share this post


Link to post
Share on other sites
[!--quoteo(post=351743:date=Mar 4 2006, 09:50 PM:name=Twentyoneth)--][div class=\'quotetop\']QUOTE(Twentyoneth @ Mar 4 2006, 09:50 PM) [snapback]351743[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I cant afford to change hosts, but I think that they might have disabled it for mass emailing from websites, but Im just having my website email me.

Is it possible to do the "ini_set" thing for the mail function?
[/quote]

No?

Share this post


Link to post
Share on other sites
HI All

I am facing the same problem.
Form my PHP code I am able to send mail to some domains except yahoo,gmail and etc.......

I searched in the forum and found a few threads.But none of them has final solution.

please find the below code.

[code]
<?php

ini_set("display_errors", "1");
ini_set("error_reporting", "E_ALL");

$headers  = "From: "    . "ravi.kotha@domain.com" . "\n";
$headers .= "Reply-To: " . "ravi.kotha@domain.com". "\n";
$headers .= "Cc: "      . "ravi_1201@yahoo.com"  . "\n";
$headers .= "Bcc: "      . "ravikumar.kotha@gmail.com"  . "\n";

$message = "message content";

$subject = "working on mailing functionality";

$to      = "ravi.kotha@domain.com,anantharavi@yahoo.co.in";

$flag    = mail($to,$subject,$message,$headers);

print "flag is $flag";
?>
[/code]


Please let me know the solution.
Appreciate your help.

thanks
Ravi Kumar

Share this post


Link to post
Share on other sites
and me also found the same problem with mail method (not send )
if any one know any good code used and explian wat is the popular wrong to help us (mail and form)

Share this post


Link to post
Share on other sites
I have found this to work the best for me. I am going to try and test your code on mine and see if it works for me. I will let you know what comes of it. Below will work with any html form.


<?php
  if ($_SERVER['REQUEST_METHOD']=="POST"){
      // In testing, if you get an Bad referer error
      // comment out or remove the next three lines
   
      foreach($_POST as $key => $val){
        if (is_array($val)){
            $msg.="Item: $key\n";
            foreach($val as $v){
              $v = stripslashes($v);
              $msg.="  $v\n";
            }
        } else {
            $val = stripslashes($val);
            $msg.="$key: $val\n";
        }
      }
      $recipient="administration@cafeexpress-o.com";
      $subject="Form submission Cafe Express-O";
      error_reporting(0);
      if (mail($recipient, $subject, $msg)){
        echo "<h1>Thank you</h1><p>Message successfully was sent to Cafe Express-O.
</p><p>We will respond to you as soon as possible.</p>\n";
        echo nl2br($input);
      } else
        echo "An error occurred and the message could not be sent.";
  } else
      echo "Bad request method";
?>

I hope this helps

Jeff

Share this post


Link to post
Share on other sites

×

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.