-5

In brief, I am trying to write a message to the user once they have submitted the contact form using php. The problem is that I am trying to style the message a bit by adding stylistic element like bold, and spacing certain lines out with <br>. It does seem to apply.

Below is the code.

$message = "Welcome". $full_name . "to Company!" . "<br>". "<br>". "<b>". " Company is 
    the mailbox for the 21st century that evolves per your need. " . "</b>". "<br>". "<br>". "
    Letting you interact with you mail by viewing and deciding what to do with it as it is received at a 
    Company location throughout North America. ". "<b>". "Please use the below information to send a mail/package to your selected address:". "</b>". "<br>". $full_name. "<br>". $address. "<br>". "To login to your dashboard, please visit the  following link"."<br>". "<a href=''http://company.com/userinterfaceSelect.php'>Your Dashboard</a>" ;

In it, there are <br>, <b>, and a link, in which none seems to apply.

Update;

<?php 
if(isset($_POST['submit'])){
    $to = $_POST['email'];// this is your Email address
    $from = "info@company.com"; // this is the sender's Email address
    $full_name = $_POST['fullName'];
        $address = $_POST['address'];

    $subject = "Welcome to company";
    $subject2 = "Copy: New Registration";
    $message2 = "New User". "<br>" .$full_name  . "\n\n" ;
    $message = "Welcome". $full_name . "to company!" . "<br>". "<br>". "<b>". " company is 
    the mailbox for the 21st century that evolves per your need. " . "</b>". "<br>". "<br>". "
    Letting you interact with you mail by viewing and deciding what to do with it as it is received at a 
    Company location throughout North America. ". "<b>". "Please use the below information to send a mail/package to your selected address:". "</b>". "<br>". $full_name. "<br>". $address. "<br>". "To login to your dashboard, please visit the  following link"."<br>". "<a href=''http://company/userinterfaceSelect.php'>Your Dashboard</a>" ;

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
 echo "Your mail has been sent successfuly ! Thank you for your feedback";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>
Jon220
  • 161
  • 1
  • 1
  • 8
  • 2
    Output how? In an e-mail to the user? On the page? Define 'seems to apply'. Etc. – Mitya Feb 06 '15 at 14:15
  • 3
    `in a php`... `stylistic element `... `It does seem to apply.`... ( ͡° ͜ʖ ͡°) – Simon Staton Feb 06 '15 at 14:16
  • Output in an email to the user – Jon220 Feb 06 '15 at 14:19
  • If you are sending the message to a browser but it is text only, the HTML formatting will not be displayed as you expect. You need to make sure that the content is send as HTML. However, that is a different question. – Marc Audet Feb 06 '15 at 14:22
  • how can i ensure the content is send as html , I just want it to be formated – Jon220 Feb 06 '15 at 14:23
  • Can you post the few lines of code showing how you are sending the email? Please update your question. Thank you. – Marc Audet Feb 06 '15 at 14:24
  • 1
    I have kindly update the code. I would also appreciate if you guys could be more generous as I am trying to learn – Jon220 Feb 06 '15 at 14:27
  • consider using a library (like phpmailer) for sending mails in php: http://stackoverflow.com/questions/4565066/why-shouldnt-i-use-phps-mail-function – Simon Hänisch Feb 06 '15 at 14:42

1 Answers1

1

You are very close to getting it to work.

You need to add a header to indicate that the content is HTML:

Content-Type: text/html; charset=ISO-8859-1

For example, your header might be formed as follows:

$headers = "From: you@yoursite.com\r\n";
$headers .= "Reply-To: me@example.com\r\n"; 
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

See the details in the references below.

References:

http://php.net/manual/en/function.mail.php

http://css-tricks.com/sending-nice-html-email-with-php/

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
  • 1
    This answer is right, but my advice would be have the HTML in an external file, place variables in a specific format in it (for example `##fullname##`). Then when you need to send the mail, load the file into a string and replace variables with the value. I think it's much cleaner and this lets you centralize HTML templates somewhere. It would also ease the translation process if needed. – Laurent S. Feb 06 '15 at 14:41
  • I agree, the OP should be using a template approach or even some type of PEAR package. As he stated, he is getting started. – Marc Audet Feb 06 '15 at 15:09
  • @Jon220 By setting the content type to HTML/text, the email client receiving the email will interpret the content as HTML and render it according to any styles you embedded in the content (inline CSS for example). How to style your message is a separate question. – Marc Audet Feb 06 '15 at 15:11