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 = "ThankYou@gameyin.com";

$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: Greetings@gameyin.com");

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

Link to comment
Share on other sites

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 = "ThankYou@gameyin.com";

$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: Greetings@gameyin.com");

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?

Link to comment
Share on other sites

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 = "ThankYou@gameyin.com";

$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: Greetings@gameyin.com");

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');
}
?>

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

Figured it out. However, if I enter

Name: Ryan

Email: diablosoccer19@excite.com

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 = "sportsdude.reese@gmail.com";

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: Greetings@gameyin.com");

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');
}
?>

Link to comment
Share on other sites

<?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 = "sportsdude.reese@gmail.com";

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: Greetings@gameyin.com");
}
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');
}
?>

Link to comment
Share on other sites

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

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.