Используйте URL со схемой. google.com
является относительным URL, например, image.jpg
.
location.replace('google.com');
location.replace('http://stackoverflow.com');
While that should work, I would strongly recommend using a prebuilt Mail/SMTP class such as Zend_Mail. While I don't think the whole Zend Framework is the cat's pajamas, I do have a very good opinion of their mail handling code.
EDIT: I should also add that using a prebuilt Mail/SMTP class will abstract almost all of the complexity/structure of multi-part emails.
Update 2009-05-06: Answering your question directly.
- Are the UTF-8 declarations and attachments well formed?
They look decent enough.
- Do I need to use
quoted_printable_decode()
? If yes, where?
No. You would want to use quoted_printable_decode()
only if you are decoding an email message. Not when you are encoding one. Should you use quoted_printable_encode()
? I will discuss this next.
- Content-Transfer-Encoding: 7 or 8 bits? I've always seen 7 but since I'm sending a UTF-8 encoded mail I'm not sure.
Only use 8bit encoding if you know that the destination SMTP server can support it. However, since you are passing your email off to the local MTA, I wouldn't recommend setting this value. The default value is 7bit encoding, but it has it's own set of restrictions: up to 998 octets per line of the code range 1-127 with CR and LF only allowed to appear as part of the CRLF line ending (http://tools.ietf.org/html/rfc2045#section-2.7).
I would recommend you use the Quoted-Printable (http://tools.ietf.org/html/rfc2045#section-6.7) Content-Transfer-Encoding. Where you are calling trim(strip_tags($message, ''))
and trim($message)
you will want to enclose those with quoted_printable_encode(trim(...))
.
- Should I use
mb_send_mail()
ormail()
is enough?
If you know you are not going to be handling Multibyte messages (Japanese, Korean, Chinese, etc.) then mail()
should suffice.
Now that I've answered your initial questions, let me tell you where some problems exist.
null
in $to
, $bcc
, $attachments
before you further process them, however, you aren't doing anything when they may actually be null
. So, if you happen to receive a null
for $to
, you don't process the variable, but you continue to send an email to null
.As of right now, that's all I am going to go into but I am still going to highly recommend a pre-built solution as they have had lots of users/time to work out bugs.
I'm all for rolling-your-own in most situations, but when it comes to mail I'd heartily recommend making it easier on yourself and using something like Swift Mailer or PHPMailer (in that order, for my money).
As a side-bonus (and assuming you specify reply-to, etc), you also have much less chance of being tagged as spam.