Need help with contact form

Discussion in 'PHP' started by mgrohan, Dec 9, 2009.

  1. #1
    Need help with a contact form i am using.

    Have tried everything but i can't get the form to send the message in html (so i can include an image). At the moment the received email will not show the image but instead shows <img src='http:// mysite .com/title.jpg' /> in the email

    Code is as follows
    <?
    
    $mailto = "contact@ mysite .com";
    $cc = "";
    $bcc = "";
    $subject = "Contact Form";
    $vname = "Name";
    
    $email = $_POST['email'];
    
    function validateEmail($email)
    {
       if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email))
    	  return true;
       else
    	  return false;
    }
    
    
    if((strlen($_POST['name']) < 1 ) || (strlen($email) < 1 ) || (strlen($_POST['message']) < 1 ) || validateEmail($email) == FALSE){
    	$emailerror .= 'Error:';
    
    	if(strlen($_POST['name']) < 1 ){
    		$emailerror .= '<li>Enter name</li>';
    	}
    
    	if(strlen($email) < 1 ){
    		$emailerror .= '<li>Enter email</li>';
    	}
    
    	if(validateEmail($email) == FALSE) {
    		$emailerror .= '<li>Enter valid email</li>';
    	}
    
    	if(strlen($_POST['message']) < 1 ){
    		$emailerror .= '<li>Enter message</li>';
    	}
    
    } else {
    
    	$emailerror .= "<span>Your email has been sent successfully!</span>"; 
    
    
    	$timestamp = date("F j, Y, g:ia");
    
    	$messageproper ="\n\n" .
    
    
    	 //
    	 //
    	 //    THE IMAGE BELOW IS THE ONE I WANT TO BE SENT IN EMAILS, AND BE SEEN ON RECEIVING THE EMAILS
    	 //
    	 //
    	 //
    
     
    		"<img src='http://www. mysite .com/title.jpg' />" .
    
    
    		"\n" .
    		"Dear Me" .
    		"\n" .
    		"You've received a new message" .
    		"\n" .
    		"\n" .
    						
    				"Name: " .
    		ucwords($_POST['name']) .
    		"\n" .
    		"Email: " .
    		ucwords($email) .
    		"\n" .
    		"Comments: " .
    		$_POST['message'] .
    		"\n" .
    				
    				"Company: " .
    		$_POST['company'] .
    		"\n" .
    		
    				"Telephone Number: " .
    		$_POST['telephone'] .
    		"\n" .
    
    		"\n\n" ;
    
    		$messageproper = trim(stripslashes($messageproper));
    		mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() );
    
    }
    ?>
    
    
    <div id='emailerror'>
    	<ul>
    		<? echo $emailerror; ?>
    	</ul>
    </div>
    Code (markup):


    +Rep :) for anyone who can help. Thanks.


    .
     
    mgrohan, Dec 9, 2009 IP
  2. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #2
    Have you added this lines in your header?
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    Code (markup):
     
    javaongsan, Dec 9, 2009 IP
    mgrohan likes this.
  3. Dondon2d

    Dondon2d Peon

    Messages:
    3,193
    Likes Received:
    146
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yup I think you just lack headers that's why it's read as plain text.
     
    Dondon2d, Dec 9, 2009 IP
    mgrohan likes this.
  4. unitechy

    unitechy Peon

    Messages:
    350
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    
    //define variables
    
    $to = //your email address
    $subject = //subject
    $headers = "MIME-Version: 1.0\r\n".
    "Content-type: text/html; charset=iso-8859-1\r\n".
    "From: Whoever";
    
    $message = "
    <html>
    <body>
    <img src=\"img src='http:// mysite .com/title.jpg\"border=\"0\" alt=\"\">
    </body>
    </html>
    ";
    
    //Send mail function
    
    mail($to,$subject,$message,$headers);
    echo "Hola! picture sent";
    
    ?>
    Code (markup):
     
    unitechy, Dec 9, 2009 IP
    mgrohan likes this.
  5. mgrohan

    mgrohan Active Member

    Messages:
    671
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Thanks Javaongsan, knew it was something simple.

    Finally got it working :) +rep


    Simple as that, can't believe i was stuck with it for so long!
     
    mgrohan, Dec 9, 2009 IP
  6. Dondon2d

    Dondon2d Peon

    Messages:
    3,193
    Likes Received:
    146
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Mistakes are normal dude, so you need not fret :D
     
    Dondon2d, Dec 9, 2009 IP