Jump to content

Recommended Posts

Hello,

 

I am new to PHP and need a little help. I created a simple PHP contact form for my website. When a person submits this form, a copy of it is emailed to me and a copy is emailed to the person submitting the form. How do I eliminate all the PHP junk from appearing in the emails?

 

For example, when I get an email copy of the form submission, the "Comments" section looks something like this:

 

Hi,\r\n\r\nThis is a test.\r\n\r\nThanks,\r\nJohn Doe

 

Is there any way for me to strip all that PHP code so it displays like this in the email instead?

 

Hi,

 

This is a test.

 

Thanks,

John Doe

 

Or, if separating the lines is difficult, just have it display like this:

 

Hi, This is a test. Thanks, John Doe

 

Any help would be greatly appreciated.

Right.  In fact, I find myself sending that so much, you are better off making your own mail function that sends all email.  That way you do not have to worry about headers at all.  Plus, you can send a copy of all email back to yourself in case somebody is spamming through your forms or whatever.

 

The prototype might be:

sendMyEmail ($toAddress, $subject, $body, $name=YOUR_SITE, $fromAddress = YOUR_EMAIL)

{

function here

}

 

That way, you can send email normally if you want, and you can optionally change the name of the sender ($name), and from address.  The constants could be used for default and changed whenever you want.

 

Inside this function, the headers and html/body closing tags will be taken care of, and all you send is the html formatted email.

 

If you change headers a lot, you could add another variable, too, for that part.

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.