Jump to content

[SOLVED] Mail function..headers sent?


GameYin

Recommended Posts

Ok, so I'm sending an email if someone wants to advertise on my website.

 

www.gameyin.com/index.html

 

Go to "Put Ad here"

 

Fill out form, and I have this for advertiseaction.php

 

 

 <?php 

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = "Advertisement on the website";
$from = "[email protected]";

$send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]");

if ($send)
{
echo 'Thank you for your interest, you will get replied to asap!';

header('Location: http://www.gameyin.com/index.php');
} else {
echo 'Your mail wasnt sent, please try again';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/100965-solved-mail-functionheaders-sent/
Share on other sites

You should know that forum members are not going to click on unknown links posted in the forum. If you don't copy and paste error messages into your post and don't get a response to your suggestion to go to your site to see them, don't get upset with the forum members.

 

Also, if you read the error message it states what the problem is. There is also a sticky post in the forum for this common noob error.

So, reading hte post, I assume that my error is that I'm echoing something to the page before I send the mail? Revising my code to...

 

<?php 

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = "Advertisement on the website";
$from = "[email protected]";

$send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]");

if ($send)
{
header('Location: http://www.gameyin.com/index.php');
} else {
header('Location: http://www.gameyin.com/advertise.php');
}
?>

 

Output...WORKS.

 

Though, using that code I gave you, It will always go to advertise.php for some reason. The mail isn't being sent. Any idea why?

cleaned up your post variables for injection and made your else an else if statement so it will know where to go ;D

 

<?php 
$name =trim(mysql_real_escape_string($_POST['name']));
$email = trim(mysql_real_escape_string($_POST['email']));
$message = trim(mysql_real_escape_string($_POST['message']));
$subject = "Advertisement on the website";
$from = "[email protected]";

$send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]");

if ($send||isset($send)||!empty($send))
{
header('Location: http://www.gameyin.com/index.php');
} else if(!$send||empty($send)||!isset($send)) {
header('Location: http://www.gameyin.com/advertise.php');
}
?>

add email function to check for validation and remove cleanup functions.

 

 

 

<?php

function check_email_address($email) {  
// First, we check that there's one @ symbol, and that the lengths are right  
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) 
{    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.  
  return false;  }
  // Split it into sections to make life easier 
$email_array = explode("@", $email);  $local_array = explode(".", $email_array[0]);  for ($i = 0; $i < sizeof($local_array); $i++) {  
   if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {   
  return false;    }  }    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name   
$domain_array = explode(".", $email_array[1]);    if (sizeof($domain_array) < 2) {  
      return false; // Not enough parts to domain    }    for ($i = 0; $i < sizeof($domain_array); $i++) {    
  if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {   
    return false;      }    }  }  return true;}


$email=check_email_adress($email);

?>

Figured it out. However, if I enter

Name: Ryan

Email: [email protected]

Message: I wanna advertise

 

The email I get is this..

 

 

Someone wants to advertise on your wetsite.

 

The user who wants to is.

 

User: Ryan

Email: 1

 

I want to advertise

 

Your welcome

 

I am using this exact code.

 

<?php
include 'config.php'; 
$name =trim(mysql_real_escape_string($_POST['name']));
$email = trim(mysql_real_escape_string($_POST['email']));
$message = trim(mysql_real_escape_string($_POST['message']));
$subject = "Advertisement on the website";
$from = "[email protected]";

function check_email_address($email) {  
// First, we check that there's one @ symbol, and that the lengths are right  
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) 
{    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.  
 return false;  }
 // Split it into sections to make life easier 
$email_array = explode("@", $email);  $local_array = explode(".", $email_array[0]);  for ($i = 0; $i < sizeof($local_array); $i++) {  
  if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {   
  return false;    }  }    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name   
$domain_array = explode(".", $email_array[1]);    if (sizeof($domain_array) < 2) {  
     return false; // Not enough parts to domain    }    for ($i = 0; $i < sizeof($domain_array); $i++) {    
 if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {   
    return false;      }    }  }  return true;}


$email=check_email_address($email);

$send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]");

if ($send||isset($send)||!empty($send))
{
header('Location: http://www.gameyin.com/index.php');
} else if(!$send||empty($send)||!isset($send)) {
header('Location: http://www.gameyin.com/advertise.php');
}
?>

<?php
include 'config.php'; 
$name =trim(mysql_real_escape_string($_POST['name']));
$email = trim(mysql_real_escape_string($_POST['email']));
$message = trim(mysql_real_escape_string($_POST['message']));
$subject = "Advertisement on the website";
$from = "[email protected]";

function check_email_address($email) {  
// First, we check that there's one @ symbol, and that the lengths are right  
if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) 
{    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.  
  return false;  }
  // Split it into sections to make life easier 
$email_array = explode("@", $email);  $local_array = explode(".", $email_array[0]);  for ($i = 0; $i < sizeof($local_array); $i++) {  
   if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {   
   return false;    }  }    if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name   
$domain_array = explode(".", $email_array[1]);    if (sizeof($domain_array) < 2) {  
      return false; // Not enough parts to domain    }    for ($i = 0; $i < sizeof($domain_array); $i++) {    
  if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {   
     return false;      }    }  }  return true;}


$email=check_email_address($email);

if($email==TRUE){

$send = mail($from , "Advertisement" , "Someone wants to advertise on your wetsite.\n\nThe user who wants to is. \n\nUser: ".$name."\nEmail: ".$email."\n\n".$message."\n\nYour welcome", "FROM: [email protected]");
}
else if($email==FALSE){ echo "The email you have is not valid or is incorrect!";}
if ($send||isset($send)||!empty($send))
{
header('Location: http://www.gameyin.com/index.php');
} else if(!$send||empty($send)||!isset($send)) {
header('Location: http://www.gameyin.com/advertise.php');
}
?>

I originally thought of that, because someone wouldn't be using a fake email address when trying to contact me to advertise on my website. Well, I'm in school, when I get home I'll try it.

 

PS: Can someone post on here just once more so I can just click on 'Show new replies to your posts'.

Last time I had to look through all of PHP Help. lol

Archived

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

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