Jump to content

[SOLVED] Form mailer issue


carley_bell

Recommended Posts

Hi,

I tested my form mailer using a "fixed" email address to make sure it works, which it did. Then I changed the "fixed" email address to a database query that gets the email address associated with the row id posted from a previous form- and I get the following error: Warning: mail() [function.mail]: SMTP server response: 503 RCPT first (#5.5.1) in D:\Hosting\3709681\html\mailer.php on line 49.

I echoed the results of the email address query and it is returning the correct email address, so I believe the problem is with the "$emailadd = $email['field_7'];" part. what am I doing wrong here?

 

p.s. I know I can have the row id translated to an email address in the form, but it can be seen when you view the source code.

 

<?php

// connect to database
include("./config.inc.php");
$row = $_POST['email'];

// get email address from row number
$query = "SELECT field_1,field_7 FROM `".$db_table."` WHERE '$row' = id";  
$result = mysql_query($query);
$email = mysql_fetch_assoc($result);

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

// Subject of email sent to you.
$subject = 'Results from Contact form'; 

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

// Where to redirect after form is processed. 
$url = ''; 

// 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'; 

// --------------------------End set parameters--------------------------
$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: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

Link to comment
Share on other sites

I'm confused by this bit;

 

$row = $_POST['email'];

// get email address from row number
$query = "SELECT field_1,field_7 FROM `".$db_table."` WHERE '$row' = id";  
$result = mysql_query($query);

 

What value is initially assigned to $row (what is $_POST['email'])

 

In your query is id the field of unique identifiers?

Link to comment
Share on other sites

i can be confusing at times so I will just post the code for the form too...

 

<div align="center"><b>CONTACT</b></div>

<form  name="contact_user2" method="POST" action="mailer.php">

<div align="left">
<b>Email</b> (enter your email address)<br>
<input name="email" type="text" size="30" maxlength="40"><br>
<b>Message</b><br>
<textarea name="mesg" cols="30" rows="5" maxlength="250"></textarea><br>



</div>

<?php
include("./config.inc.php");
$row = $_POST['row'];

// get email from row number
$query = "SELECT field_1,field_7 FROM `".$db_table."` WHERE '$row' = id";  
$result = mysql_query($query);
$email = mysql_fetch_assoc($result); 
?>

<input name="subject" type="hidden" value="Information regarding part # <?php echo $email['field_1']; ?>">
<input name="email" type="hidden" value="<?php echo $row; ?>">
<input type="submit" name="submit" value="Send" />
</form>

Link to comment
Share on other sites

Was just making sure.... the naming of things were causing worries.

 

Before;

 

mail($emailadd, $subject, $text, 'From: '.$emailadd.'');

 

can you do this...

<?php
echo <<<EOF
$emailadd <br />
$subject <br />
$text <br />
From: $emailadd
EOF;
exit;

 

and post what was printed to screen

Link to comment
Share on other sites

The problem at the moment is the way you're using carriag returns and line feeds, try the following (full code);

 

<?php

// connect to database
include("./config.inc.php");
$row = $_POST['email'];

// get email address from row number
$query = "SELECT field_1,field_7 FROM `".$db_table."` WHERE '$row' = id";  
$result = mysql_query($query);
$email = mysql_fetch_assoc($result);

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

// Subject of email sent to you.
$subject = 'Results from Contact form'; 

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

// Where to redirect after form is processed. 
$url = ''; 

// 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'; 

// --------------------------End set parameters--------------------------
$text = "Results from form:\r\n\r\n";
$space = ' ';
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 .= ' ';
}
$conc = "{$key}:{$space}{$value}\r\n";
$text .= $conc;
$space = ' ';
}
if(mail($emailadd, $subject, $text)){
die('mail sent');
} else {
die('mail not sent');
}
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>

Link to comment
Share on other sites

You can change this;

 

if(mail($emailadd, $subject, $text)){

  die('mail sent');

} else {

  die('mail not sent');

}

 

to this....

 

if(!mail($emailadd, $subject, $text)){
   die('There was an error sending the email.');
}

 

and we can try and add the from field back in;

 

if(!mail($emailadd, $subject, $text, "FROM: no-reply@your-domain.com")){
   die('There was an error sending the email.');
}

 

 

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.