Jump to content

Please help PHP ()mail function


Yamaha32088

Recommended Posts

This should be quite simple for alot of you to solve the first set of code works perfect everything below the first code box does not

 

<?php
// --- CONFIG PARAMETERS --- //
//
   $email_recipient = "test@blah.com";
   $email_sender = "mywebhostingaccount@blah.com";
   $email_return_to = "mywebhostingaccount@blah.com";
   $email_content_type = "text/html; charset=us-ascii";
   $email_client = "PHP/" . phpversion();
//
// ------------------------- //

// --- DEFINE HEADERS --- //
//
   $email_header = "From: " . $email_sender . "\r\n";
   $email_header .= "Reply-To: " . $email_return_to . "\r\n";
   $email_header .= "Return-Path: " . $email_return_to . "\r\n";
   $email_header .= "Content-type: " . $email_content_type . "\r\n";
   $email_header .= "X-Mailer: " . $email_client . "\r\n";
//
// ---------------------- //

// --- SUBJECT AND CONTENTS --- //
//
   $email_subject = "Test email subject";
   $email_contents = "<html>";
   $email_contents .= "<h2>Test Email</h2>";
   $email_contents .= "<br><b>Sender: " . $email_sender;
   $email_contents .= "<br><b>Recipient: " . $email_recipient;
   $email_contents .= "</html>";
//
// ---------------------------- //

$email_result = mail($email_recipient, $email_subject, $email_contents, $email_header);
if ($email_result) echo "Email has been sent!";
else echo "Email has failed!";
?>

 

 

 

 

The problem is when i try to use other codes such as this

 

<?php 
/* 
Name=Easy Form Mailer 
Version=1.5 
Date= November 14, 2006 
Developer=Md. Zakir Hossain (Raju) 
Email=rajuru(at)gmail(dot)com 
URL=http://www.rajuru.xenexbd.com 
License: LGPL 
I appreciate the email's last credit line but not mandatory. A thank is highly deserved 
*/ 
print_r($_POST); 

//check for 3 required fields, these fields are made with Case-sensitivity 
if(empty($_POST['Email_Recipient'])) die("No Email Recipient"); 
if(empty($_POST['Email_Sender'])) die("No Email Sender"); 
if(empty($_POST['Email_Subject'])) die("No Email Subject"); 

$to=$_POST['Email_Recipient']; 
$from=$_POST['Email_Sender']; 
$subject=$_POST['Email_Subject']; 
unset($_POST['Email_Recipient']); 
unset($_POST['Email_Sender']); 
unset($_POST['Email_Subject']); 


//success message, you can define one with hidden field. hidden field name must be "Email_Success" 
if(!empty($_POST['Email_Success'])) { 
    $success=$_POST['Email_Success']; 
} else { 
    $success= "Form submitted Successfully"; 
} 
unset($_POST['Email_Success']); //unset this variable 

//Failure message, you can define one with hidden field. hidden field name must be "Email_Failure" 
if(!empty($_POST['Email_Failure'])){ 
    $failure=$_POST['Email_Failure']; 
} else { 
    $failure="Form submission failed. Sorry for this inconvenience"; 
} 
unset($_POST['Email_Failure']); //unset this variable 

//set return url after successfully completing submission 
if(!empty($_POST['Return_Url'])){ 
   $returnurl=$_POST['Return_Url']; 
} else { 
  $returnurl=$_SERVER['HTTP_REFERER']; 
} 
unset($_POST['Return_Url']);     //unset return url 

$msg=""; 

foreach ($_POST as $Field=>$Value){ 
    if(substr($Field,0,2)=="__"){ //field started with double underscore which means they are required fields 
        if(empty($Value)){ 
        die("You must enter ".substr($Field,2)."<br/><a href=\"javascript:history.go(-1)\">Go Back</a>");     //cancel script 
        } else { 
            $msg .= substr($Field,2) .": <b>". $Value."</b>";      //strip first two character as they are double underscore 
               $msg .="<br>"; 
        } 
    } else { 
        $msg .= $Field .": <b>". $Value."</b>"; 
           $msg .="<br>"; 
    } 
} 
$msg.= "<br/><br/>Script by <a href=\"http://www.rajuru.xenexbd.com\">Md. Zakir Hossain (Raju)</a>";    

        /* To send HTML mail, you can set the Content-type header. */ 
        $headers  = "MIME-Version: 1.0\r\n"; 
        $headers .= "Content-type: text/html; charset=iso-8859-1 \r\n"; 
        
        /* additional headers */ 
        $headers .= "To: $to \r\n"; 
        $headers .= "From: $from \r\n"; 
        $headers .= "Subject: $subject \r\n"; 
        
        
        /* and now mail it  */ 
        if (@mail($to,$subject, $msg, $headers)) { 
        echo "<b>$success</b><br/><a href=\"$returnurl\">Go Back</a>"; 
        } else     { 
        echo "$failure <br/><a href=\"javascript:history.go(-1)\">Go Back</a>"; 
        } 


?>

 

 

 

The following code below was the html i was using for the form for the above code code box #2 and it still does not work

 

<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> 
<meta http-equiv="Content-Language" content="en-us"> 
<title>Form Submission</title> 
</head> 
<body> 
<hr> 
<form action="mailer.php" method="POST" enctype="multipart/form-data"> 
<h2>Form Submission Sample</h2> 
    <p>Make up a username:<br> 
    <input type="text" size="25" maxlength="256" name="__Username"> -- <em>you 
    can use mixed case</em><br> 
    Make up a password:<br> 
    <input type="password" size="25" maxlength="256" name="__Password"> -- <em> 
    help keep this private!</em><br> 
    Enter password again:<strong><br> 
    </strong> 
    <input type="password" size="25" maxlength="256" name="__PasswordVerify"> -- 
    <em>for verification</em><br> 
    Enter e-mail address:<strong><br> 
    </strong><input type="text" size="25" maxlength="256" name="__EmailAddress"> 
    -- <em>if you have one</em></p> 
    <p><input type="text" size="25" maxlength="256" name="Firstname"> - First 
    Name</p> 
    <p><input type="text" size="25" maxlength="256" name="Lastname"> - Last Name</p> 
    <h2><input type="submit" value="Register Me"> 
    <input type="reset" value="Clear Form"></h2> 
    <input type="hidden" name="Email_Recipient" value="test@blah.com"> 
    <input type="hidden" name="Email_Sender" value="mywebhostingaccount@blah.com"> 
    <input type="hidden" name="Email_Subject" value="Membership Request"> 
    <input type="hidden" name="Email_Success" value="Request Submitted, thanks for your time"> 
    <input type="hidden" name="Email_Failure" value="An unknown error occured while submitting your form."> 
    <input type="hidden" name="Return_Url" value="<?php echo $_SERVER['HTTP_REFERER'];?>"> 

</form> 
<hr> 
</body> 
</html>

 

 

 

 

 

i have tryed every single simple form and php mailer out there a simple script like this doesnt even work

 

 

<?php$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";?> 

 

 

Please help me out!?!?!?!?!

 

 

Link to comment
Share on other sites

Try this!

<?php

$email = "someone@example.com";

$subject = "Test mail";

$message = "Hello! This is a simple email message.";

 

$headers.= "From: someonelse@example.com\n";

$headers.= "X-Priority: 2\n";

$headers.= "MIME-Version: 1.0\n";

$headers.= "Content-Type: text/html; charset=iso-8859-1\n";

 

if(mail($email, $subject, $message, $headers));

Link to comment
Share on other sites

What are you testing it on? If it is on localhost, make sure you set the email settings in your php.ini file correctly.

 

I got this code to work, Try it.

<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse@example.com";
$headers = "From: " . "Richie" ." " . " <" . $from .">\r\n";
$headers .= "Reply-To: " . $from . "\r\n";
$headers .= "Return-path: " . $from;
mail($to, $subject, $message, $headers);
echo "Mail Sent.";
?>

Link to comment
Share on other sites

ok awsome i got the code to work and it sends from flash here is the modified code BUT there is another problem when it sends to me thier first and last name does not show up only the email address does any ideas???

 

<?php
$to = "Mototips@cableone.net";
$subject = "fuck off";
$message = $_POST["message"];
$from = "Administrator@mx2pros.com";
$headers = "From: " . $_POST["firstName"] ." ". $_POST["lastname"] . "<" . $_POST["email"] .">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-path: " . $_POST["email"];
mail($to, $subject, $message, $headers);
echo "Mail Sent.";
?>

Link to comment
Share on other sites

  • 2 weeks later...
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.