Jump to content

PHP Form Headers (?)


codenoobie

Recommended Posts

*Note: Blade280891 just answered this question on my earlier post. He said that I can't do this without PHPMailer. So, I guess that's my answer. Thank you

 

This is actually part two of an earlier post. I figured I'd do it this way because the question is different from the original.

 

I'm in trouble here. I'm a newbie at PHP I'm going to have to really learn PHPMailer as soon as I can. But, I'm really under the gun timewise (I'm pregnant and due tomorrow - if I don't get this site done by the time this baby comes I'm in real trouble with my boss.) Is there anyway to add headers to this code that will customize the "from" email address to say "TEAM:BARIATRICS" instead of "[email protected]" easily? I can't figure it out without help. I've been trying to all day and I'm so new at this I'm not having luck at all:

 

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'TEAM:BARIATRICS Informational Packet Request';

// Your email address. This is where the form information will be sent.
$emailadd = '[email protected]';


// Where to redirect after form is processed.
$url = 'http://www.butneveragain.org/info/thankyou.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// Email address put into Email Field

$email_field = $_POST["Email"]; 





// --------------------------Do not edit below this line--------------------------
$auto_respond_subject = 'TEAM:BARIATRICS Informational Packet Request';
$auto_respond_body = "Thank you for requesting your free TEAM:BARIATRICS Informational Packet. \n
You should recieve your packet within 5-10 business days.\n If you would like additional information, call 574.537.TEAM or visit us online at www.butneveragain.org.";
mail($email_field, $auto_respond_subject, $auto_respond_body);
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
	if ($value == '')
	{
		echo "$key is empty";
		die;
	}
}
$j = strlen($key);
if ($j >= 20)
{
	echo "Name of form element $key cannot be longer than 20 characters";
	die;
}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{
	$space .= ' ';
}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, "From: Online Request");

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';


?>
Link to comment
https://forums.phpfreaks.com/topic/118168-php-form-headers/
Share on other sites

Try this:

<?php
//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'TEAM:BARIATRICS Informational Packet Request';

// Your email address. This is where the form information will be sent.
$emailadd = '[email protected]';


// Where to redirect after form is processed.
$url = 'http://www.butneveragain.org/info/thankyou.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// Email address put into Email Field

$email_field = $_POST["Email"]; 

//Here is where I set the headers, you can add more if ever necessary 
$headers = "From: Team:Bariatrics <[email protected]>";


// --------------------------Do not edit below this line--------------------------
$auto_respond_subject = 'TEAM:BARIATRICS Informational Packet Request';
$auto_respond_body = "Thank you for requesting your free TEAM:BARIATRICS Informational Packet. \n
You should recieve your packet within 5-10 business days.\n If you would like additional information, call 574.537.TEAM or visit us online at www.butneveragain.org.";
mail($email_field, $auto_respond_subject, $auto_respond_body, $headers);
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
	if ($value == '')
	{
		echo "$key is empty";
		die;
	}
}
$j = strlen($key);
if ($j >= 20)
{
	echo "Name of form element $key cannot be longer than 20 characters";
	die;
}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{
	$space .= ' ';
}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, "From: Online Request");

echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';


?>

Link to comment
https://forums.phpfreaks.com/topic/118168-php-form-headers/#findComment-607988
Share on other sites

I wrote this a long time ago, but I remember it working:

$fp = fsockopen("mail.server.com", 25, $errno, $errstr, 30);
if (!$fp)
	die("Mail server could not be contacted. Please try again later.");
else
{
	$out = "HELO\r\n";
	$out .= "MAIL FROM: [email protected]\r\n";
	$out .= "RCPT TO: [email protected]\r\n";
	$out .= "DATA\r\n";
	$out .= "SUBJECT: Subject\r\n";
	$out .= "MESSAGE-ID: Extra info\r\n\r\n";
	$out .= "body of message\r\n";
	$out .= ".\r\n";
	$out .= "quit\r\n";
	fwrite($fp, $out);
	fclose($fp);
}

 

You should be able to change the MAIL FROM: part to any name you want, but some mail servers have rules for that name.

 

Good luck!

Link to comment
https://forums.phpfreaks.com/topic/118168-php-form-headers/#findComment-607999
Share on other sites

Sure! Here goes:

 

<?php

//--------------------------Set these paramaters--------------------------

// Subject of email sent to you.
$subject = 'TEAM:BARIATRICS Informational Packet Request';

// Your email address. This is where the form information will be sent.
$emailadd = '[email protected]';

// Where to redirect after form is processed.
$url = 'http://www.butneveragain.org/info/thankyou.html';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';

// Email address put into Email Field
$email_field = $_POST["Email"]; 

//Here is where I set the headers, you can add more if ever necessary 
$headers = "From: Team:Bariatrics <[email protected]>";

// --------------------------Do not edit below this line--------------------------
$auto_respond_subject = 'TEAM:BARIATRICS Informational Packet Request';
$auto_respond_body = "Thank you for requesting your free TEAM:BARIATRICS Informational Packet. \n
You should recieve your packet within 5-10 business days.\n If you would like additional information, call 574.537.TEAM or visit us online at www.butneveragain.org.";
mail($email_field, $auto_respond_subject, $auto_respond_body, $headers);
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
	if ($value == '')
	{
		echo "$key is empty";
		die;
	}
}
$j = strlen($key);
if ($j >= 20)
{
	echo "Name of form element $key cannot be longer than 20 characters";
	die;
}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{
	$space .= ' ';
}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, "From: Online Request");
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

Link to comment
https://forums.phpfreaks.com/topic/118168-php-form-headers/#findComment-608014
Share on other sites

I'll try to post it again... Here it is. This is so strange.

<?php
//--------------------------Set these paramaters--------------------------
// Subject of email sent to you.
$subject = 'TEAM:BARIATRICS Informational Packet Request';
// Your email address. This is where the form information will be sent.
$emailadd = '[email protected]';
// Where to redirect after form is processed.
$url = 'http://www.butneveragain.org/info/thankyou.html';
// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '0';
// Email address put into Email Field
$email_field = $_POST["Email"]; 
//Here is where I set the headers, you can add more if ever necessary 
$headers = "From: Team:Bariatrics <[email protected]>";

// --------------------------Do not edit below this line--------------------------
$auto_respond_subject = 'TEAM:BARIATRICS Informational Packet Request';
$auto_respond_body = "Thank you for requesting your free TEAM:BARIATRICS Informational Packet. \n
You should recieve your packet within 5-10 business days.\n If you would like additional information, call 574.537.TEAM or visit us online at www.butneveragain.org.";
mail($email_field, $auto_respond_subject, $auto_respond_body, $headers);
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
	if ($value == '')
	{
		echo "$key is empty";
		die;
	}
}
$j = strlen($key);
if ($j >= 20)
{
	echo "Name of form element $key cannot be longer than 20 characters";
	die;
}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{
	$space .= ' ';
}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, "From: Online Request");
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

Link to comment
https://forums.phpfreaks.com/topic/118168-php-form-headers/#findComment-608034
Share on other sites

Hmm, okay.  What I did was first of all add a check to make sure that the email address was sent to the page, otherwise redirect back to the index.html page (otherwise the mail() call will mess up).  And then I just uploaded it, and it's not erroring any more.  Try filling out the form and get back to me.

Link to comment
https://forums.phpfreaks.com/topic/118168-php-form-headers/#findComment-608058
Share on other sites

First of all, I added this (albeit rudimentary) check to the top just to make sure that the mail gets to where it has to go:

if (!$_POST['Email']) {

header('Location: index.html');

}

 

Secondly, I set up the $headers variable, and used it as the 4th parameter of mail():

$headers = "From: Team:Bariatrics <[email protected]>";

mail($email_field, $auto_respond_subject, $auto_respond_body, $headers);

 

And that's all that I really did.  I honestly have NO idea why it was giving you that error, and I've been doing this for quite a while. o-O

 

Glad I could help, and good luck with your child (you'll need it).

 

Also, if you need help with something that you just can't seem to get working, PM me and I'll probably be able to help a bit.

Link to comment
https://forums.phpfreaks.com/topic/118168-php-form-headers/#findComment-608075
Share on other sites

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.