How to get a Clickable Link inside this text string?

Hi guys, here again is a generic version of the script again that no matter what I do it always sends me a text based email with the code and not an HTML email with the LINK…My Hosting is of no help as they don’t trouble shoot scripts and say everything is fine on their end… LOL…Please test the script on one or your own domains to prove that it will send the HTML LINK successfully on a good Hosting Company :slight_smile: …Please let me know Thank you!

<?php
$msg="";
if(isset($_POST['submit']))
{
	$from_add = "support@XXXXXXXXXX.com"; 
	$to_add = "support@XXXXXXXXXX.com";

	$subject = "Test Subject";
	
	$message = "Test Email Message - Click Here: <a href='https://www.google.com'>Test</a>";
		
	$headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
	//$headers  = 'MIME-Version: 1.0' . "\r\n";
        //$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	$headers = "From: $from_add \r\n";
	$headers .= "Reply-To: $from_add \r\n";
	$headers .= "Return-Path: $from_add\r\n";
	$headers .= "X-Mailer: PHP \r\n";
	
	
	if(mail($to_add,$subject,$message,$headers)) 
	{
		$msg = "Mail sent OK";
	} 
	else 
	{
 	   $msg = "Error sending email!";
	}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>Test form to email</title>
</head>

<body>
<?php echo $msg ?>
<p>
<form action='<?php echo htmlentities($_SERVER['PHP_SELF']); ?>' method='post'>
<input type='submit' name='submit' value='Submit'>
</form>
</p>

</body>
</html>

for sending anything beyond a simple text mail I strongly recommend to use a mailing library (SwiftMailer, PHPMailer), otherwise you would have to sift through all the email related RFCs to find the principal issue.

1 Like

Hi Dormillich, I’ve tried the PHPMailer but the script just gave me:

The page isn’t working
sample.com is currently unable to handle this request.
HTTP ERROR 500

Can anyone provide me with a working PHPMailer script that does SMTP because that is what I need in order for the email to come directly from my domain? Please advise…Thank you!

I only use SwiftMailer, so I can’t give advice about PHPMailer. but I would expect that their documentation has a working example.

One thing I notice that may or not be involved with the problem is the email header.

AFAIK email clients use two newlines as the indication that the header section is done. eg.

$headers .= "X-Mailer: PHP \r\n\r\n";
1 Like

@Mittineague nope. see RFC 2822 section 2.2

Header fields are lines composed of a field name, followed by a colon
(“:”), followed by a field body, and terminated by CRLF.

1 Like

I meant the separation between the headers and the message body.
i.e. 2.1

A message consists of header fields (collectively called “the header
of the message”) followed, optionally, by a body. The header is a
sequence of lines of characters with special syntax as defined in
this standard. The body is simply a sequence of characters that
follows the header and is separated from the header by an empty line
(i.e., a line with nothing preceding the CRLF).

1 Like

sorry, didn’t catch that.

but essentially, this is proof that you should leave this matter to battle-tested mailing libraries.

2 Likes

Hi guys, thanks again for all your help!

I finally got PHPMailer working and it works good however I a having a very hard time passing a simple variable into the Body of the email message.

$cust-name = “John Doe”;

$mail->Body = ‘Hello $cust-name’;

I can’t pass a simple variable I created into the message. Please let me know if you have any thoughts?

Of course the actual application is more complicated as I’m pulling the cust-name from data on another system but essentially this is all I’m trying to do here…Please advise…Thanks

You’re seeing the literal string Hello $cust-name OK?

PHP variables are not interpreted when inside single quotes.

Try using double quotes or concatenation eg. either of these should work

$mail->Body = "Hello $cust-name";
$mail->Body = 'Hello ' .  $cust-name;
2 Likes

Thank you for the reply Mittineague!

That was it…now everything is working. :slight_smile:

Thank you everyone that has responded to my question!!!

Regards,
jhdl17

One last thing with PHPmailer…I got tired updating the file local and then FileZilla (FTP) to my server so I could run the program to send out the emails one at a time. So I setup a Form…everything works except now on my blind carbon copy it says the following:

To: undisclosed-recipients:

Please help me change this so I can see exactly who I’ve have sent my email to?

Thank you!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.