Jump to content

email script


Twentyoneth

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?
Link to comment
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]
Link to comment
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.
Link to comment
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...
Link to comment
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?
Link to comment
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.
Link to comment
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.
Link to comment
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.
Link to comment
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
Link to comment
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
Link to comment
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?
Link to comment
Share on other sites

  • 6 months later...
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.