image in email just printing url - php

I have a simple php email script where I wish to include an image at the bottom. When I add the image tags like below the email just shows <img src="http://domain.com/images/logo.png" /> instead of the actual image. Any ideas why?
<?PHP
$email = $_POST["emailaddress"];
$to = "you#youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$headers .= "Content-type: text/html\r\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: info#domain.com\n";
$usermessage =
"
Thank you for joining our mailing list.
We hope to see you very soon!
Address 1
Address 2
<img src=\"http://domain.com/images/logo.png\" />
";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
$fh = fopen("email.xml", "a");
fwrite($fh, "$email\r\n");
fclose($fh);
?>

You're not passing the Content-Type header with the right message. $headers does contain the right header, but it is sent with a plain text message, whereas $userheaders does not contain the Content-Type header, but the message associated with it does contain some HTML
Replace
$userheaders = "From: info#domain.com\n";
with
$userheaders = "From: info#domain.com\r\n";
$userheaders = "Content-type: text/html\r\n";
and it should work perfectly

This is a word press plugin but if you delete everything BUT the XmailBaby class it should work for you nicely.
That code is a nice piece of work that sends emails very good.
It is just a basic version but it should be enough for you.
Take a look through the code, you might find it interesting.
http://plugins.svn.wordpress.org/xmail-the-right-way/trunk/xmail.php

You need to specify html headers. Rather than do this yourself, you can use a well-established method that supports sending HTML emails, such as PHPMailer:
http://phpmailer.worxware.com/

Related

sendmail.php file isnt working right?

so I'm new at this website stuff and im doing at part of my uni course, my tearcher gave me the code.
This in my code for my sendmail.php I tested my contact form on my website and I get the 'Failure!' message that is in the code but that is all I get, nothing else.
when it was working I would get the email but know information that was put in to the contact form and I haven't change the coding. could someone please help me? Thank you
<?php
/*Here you are going to declare the variables*/
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
//Save visitor name and entered message into one variable:
$formcontent="VISITOR NAME: $name\\n\\nFEEDBACK: $message";
$recipient = "denisedaykinphotography#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email\\r\\n";
$mailheader .= "Reply-To: $email\\r\\n";
$mailheader .= "MIME-Version: 1.0\\r\\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Failure!");
echo "Thank You!";
?>
Keep your $variables outside of "strings".
meaning:
$name = "Bob";
"hello $name" != "hello " . $name;
It is highly likely that hosting/your computer where the script is put at the moment doesn't support sending mails.
If this is your computer, you could put use to this answer I provided in a similar thread and setting up your own SMTP server (that is the service responsible for sending emails), or using a free one from Internet.
If this is not your computer and you can not really change configs/server configuration, etc., then I suggest you to move the script somewhere else.
The value of variable $mailheader is wrong. Now, an echo($mailheader) displays something like:
From: user#example.org\r\nReply-To: user#example.org\r\nMIME-Version: 1.0\r\n
which is wrong.
The header lines must be separated by the <CR><LF> pair of characters, i.e. the characters having the codes 13 and 10. Because they are not printable, in PHP double-quoted strings these characters are encoded as "\r" and "\n".
The same remark about the content of you message.
Regarding this issue, the code should look like this:
$formcontent = "VISITOR NAME: $name\n\nFEEDBACK: $message";
$recipient = "denisedaykinphotography#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email\r\n";
$mailheader .= "Reply-To: $email\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";
These answer does not really address your problem of mails not being sent but, before checking the PHP configuration and other mail-related issues, make sure the values you provide to PHP mail() function are correctly formatted (as explained above).

How to secure a contact form in PHP

I'm not php savvy, can someone please provide a good strong code that I can use tailored for my form to prevent injections into my script? I would need to know exactly where to insert this code within my existing code.
My code is below. I left off the opening and ending php tags so all of the code would be visible.
$name=addslashes($_POST['name']);
$email=addslashes($_POST['email']);
$website=addslashes($_POST['website']);
$services=addslashes($_POST['services']);
$comments=addslashes($_POST['message']);
// you can specify which email you want your contact form to be emailed to here
$toemail = "email#domainname.com"; $subject = "Creative Design Consultation Request";
$headers = "MIME-Version: 1.0\n" ."From: \"".$name."\" <".$email.">\n" ."Content-type: text/html; charset=iso-8859-1\n";
$body = "Name: ".$name."\n"
."Email: ".$email."\n"
."Website: ".$website."\n"
."Services: ".$services."\n"
."Comments:\n".$comments;
mail($toemail, $subject, $body, $headers);
echo "Thank you for submitting your request";
This might be what you're looking for:
Sanitize filters php

E-mail parsing addresses with junk characters

I'm sending e-mails through a form I coded and for some reason, for some cases the e-mail address becomes junk, and for other times it works fine.
//on form page
$message = str_replace("#e",$emtemail,$message);
$message is stored in SQL (defined on another page), same for $emtemail. $message is just the body of the e-mail being sent, and I'm replacing all instances of #e with the e-mail people send payments to. It sends one e-mail to the customer, and one e-mail to me.
//customer e-mail
//the display address might appear as payment52.62gmail.com instead of payment#gmail.com
//my e-mail
//all e-mail addresses formatted properly without error, # appears as #
Why do e-mail addresses parse strangely? Something to do with encoding?
This is all of the code relevant to sending e-mails I have. I can't pinpoint the problem.
//any variables used in the below but not declared are previously initialized
$em = $userc["email"];
$subject = $emailone["subject"];
$subject = str_replace("#o",$ordernum,$subject);
$subject = str_replace("#u",htmlspecialchars($rn),$subject);
$subject = str_replace("#g",$gt,$subject);
$subject = str_replace("#sl","www.SZVapor.com",$subject);
$subject = str_replace("#ss","SZVapor.com",$subject);
$subject = str_replace("#st","SZVapor",$subject);
$message = nl2br($emailone["message"]);
$message = str_replace("#o",$ordernum,$message);
$message = str_replace("#u",htmlspecialchars($rn),$message);
$message = str_replace("#t",$table,$message);
$message = str_replace("#e",$emtemail,$message);
$message = str_replace("#g",$gt,$message);
$message = str_replace("#a",$addrsubmit,$message);
$message = str_replace("#sl","www.SZVapor.com",$message);
$message = str_replace("#ss","SZVapor.com",$message);
$message = str_replace("#st","SZVapor",$message);
$message = str_replace("#c",$em,$message);
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1"."\r\n";
$headers .= "From: no-reply#SZVapor.com";
mail($em, $subject, $message, $headers);
Some examples of e-mail addresses given:
payment62.44gmail.com
payment54.45gmail.com
payment22.59gmail.com
payment25.49gmail.com
http://php.net/manual/en/function.mail.php
The first parameter entry for mail is the email address.
The code above does not do anything with $em
And by the way, I think that the last header line should look like this:
$headers .= "From: no-reply#SZVapor.com" . "\r\n";
I solved the issue, and it was an error on my part. I was replacing all instances of certain character combinations with variables.
#g = replaced with grand total
#e = replaced with payment e-mail
#o = replaced with order number
etc
The order I did them in was such that I replaced #e with the e-mail payment#gmail.com, and then replaced all #g with the grand total, so payment*#g*mail.com became "payment".$grandtotal."mail.com".

using the PHP mail function

I am using the PHP mail function to send my users emails about new features and updates. I can send an email and message no problem. But I would like to control who the message is from, well more who the Email Client says it is from.
For Example:
<?php
$to = "someone#gmail.com";
$subject = "Test";
$msg = "Hello there!";
$headers = "From: someone#shareit.me";
mail($to,$subject,$msg, $headers);
?>
In the mail client (Ie. Gmail) the user will see:
Someone Test - Hello There
I would like to control the name of the sender via my headers. Is that possible?
So the email will be from someone#shareit.me but the name of the sender will be Shareit.
Thanks
Use the following headers: (link to docs)
$headers = "From: Shareit <someone#shareit.me>";
To use the From attribute inside of headers always remember to keep email addresses inside of these brackets: < and >
So now your email would be: <someone#shareit.me>
and your line would be: $headers = "From: <someone#shareit.me>"
or "From: Shareit <someone#shareit.me>"
$headers = "From: Shareit <someone#shareit.me>";
Try the above code.
Change the name from Shareit to the name of your choice.

PHP Mail Send when using a tag

PHP mail sending problem when using a tag, it doesn't come to new line.
HERE is my code having same problem
$subject = 'Watch Out Our Colorful Web Design Presentation';
$headers = "From: " . $email . " \r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "Bcc: test#test.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "Watch Out Our Colorful Web Design Presentation.\r\n";
$message .= "<a href='http://www.stackoverflow.com'>CLICK HERE</a>\r\n";
mail($to, $subject, $message, $headers);
Mail send successfully but having problem in \r\n. It doesn't take new line. I tried br tag too. But it goes in junk mail.
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
You're sending a HTML email. This means that you should be using HTML instead of newlines. To avoid having your emails placed in the junk folder, you should read some of the many Stackoverflow topics on the subject.
You have to use <br> tag for new line.
You can't use \n for new line for html printing.
https://bugs.php.net/bug.php?id=9542
As others have said, you need to be using HTML line breaks <br /> if you are sending an e-mail with Content-Type: text/html. The newlines/carriage returns will be interpreted in the source of the message as line breaks but they will probably not be rendered as HTML.
When sending e-mail from PHP I would always suggest using an e-mail class rather than PHP's native mail functions.
I tend to use SwiftMailer. It has the advantage that all mail headers are sanitized and escaped to avoid header injection exploits that could potentially fire out spam through your script. Also it's easier to use a variety of e-mail transports. There's also a great decorator plugin which can send thousands of messages with customised strings, useful for doing things like "Dear {first_name} {surname}" or customised unsubscribe/tracking links.
Here's some sample code for SwiftMailer just in case you are interested...
// START SWIFTMAILER
require_once($swiftmailer_path);
$swift_transport = Swift_SendmailTransport::newInstance($sendmail_cmd);
$swift = Swift_Mailer::newInstance($swift_transport);
$swift_msg = Swift_Message::newInstance($swift_transport);
$swift_msg->setMaxLineLength(150);
$swift_msg->setFrom( array('NoReply#domain.com' => 'MyWebsiteName'));
$swift_msg->addTo($user);
$swift_msg->setSubject($subject);
$swift_msg->setBody($msg_html, 'text/html');
$swift_msg->addPart($msg_txt, 'text/plain');
// SEND E-MAIL
if ($swift_result = $swift->send($swift_msg)) {
// SENT SUCCESSFULLY
} else {
// ERROR - E-MAIL NOT SENT
}

Categories