0

time for a new project... i have a server that has a limit to the number of emails it can send out in a day so i thought maybe i should have the forms drop them into the database and email them as one message once a day as a single message broken by line breaks as oposed to a new message each time a form is submitted. my submission form works, as well as my look up. my while statement pulls the data out and if i echo it it shows perfectly. the only touble i am having is when i try to put the array into the mail() function. also it dows email me everytime, just with no content each time.

my while statement is as follows (with the echo left in):

while ($ctform_row = mysql_fetch_array($ctform_query, MYSQL_ASSOC)) {
echo $ctform_row['name']." - ".$ctform_row['email']." - ".$ctform_row['Phone']." - ".$ctform_row['message']." - ".$ctform_row['date']."<br />";
}

i tried to replace the echo with $message and it shows me a line at random in the email. what am i doing wrong? my form mail function is as follows:

mail($destination, $subject, $message);

Where my subject and destination are already set.

2
  • and how do you set your strings? Show us your complete code please! Commented Oct 5, 2012 at 21:39
  • Maybe add the lines all together by replacing the echo with: $message.=$ctform... Commented Oct 5, 2012 at 21:40

2 Answers 2

1

Without seeing your code your description leads me to believe that you're using the assignment operator rather than the concatenation operator.

i.e. you're doing this:

$message = $ctform_row['name']." - ".$ctform_row['email']." - ".$ctform_row['Phone']." - ".$ctform_row['message']." - ".$ctform_row['date']."<br />";

and you should be doing this:

$message .= $ctform_row['name']." - ".$ctform_row['email']." - ".$ctform_row['Phone']." - ".$ctform_row['message']." - ".$ctform_row['date']."<br />";

Note the .=

Just make sure you define $message before entering the while loop ($message = "";)

Sign up to request clarification or add additional context in comments.

1 Comment

that worked perfectly! thanks! now to make the email look good, as of now its just lines of text with little to no formatting.
0

You say it emails you everytime and I guess that is a problem for you. You should put all the code for collecting, sending and clearing (?!) the data in a separate PHP file, then make a cronjob on your server to send you the email every day.

3 Comments

not everytime a form is submitted but i mentioned that it emailed me to say that the basic functionality of the mail() function works.
@user1258619 OK, this sounded to me was a problem as you wrote this after "the only trouble..."
lol, sorry about that... im a bit of a scatter brain sometimes. you should see my code before i clean it up...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.