link is not showing in email body in php - email

I am trying to to use a link in my email body but failed to do that, Whenever i send an email, email is sent but it contain only the plain text but i also want to print a link so that that link will redirect me to another page.
here is my php code,
<?php
include("admin/config.php");
$email=$_POST['email'];
/// mail to customer
$to=$email;
$subject="Thanks for Contacting with us";
// Message
$message = '
<html>
<head>
<title>Request to Change Password</title>
</head>
<body>
<p>You have requested to change password <br> Please follow the below link to change your password.<br><br></p>
<p>Change Password<br><br></p>
<p>Regards<br></p>
<p>http://www.example.com<br></p>
<p>9999999999<br></p>
</body>
</html>
';
$from = 'MIME-Version: 1.0' . "\r\n";
$from.= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$from.= 'From: <no-reply#abc#gmail.com>' . "\r\n";
$mail =mail($to,$subject,$message,$from);
if ($mail == true){
header('location:forgot_password.php');
}
?>
Please help me out, thanks in advance

The link is not "showing" because you wrapped it in a <p> tag which is for text (paragraph) only. Wrap the link in a <a> tag and set the href attribute accordingly :
<a href="your link">
A descriptive texte or your link again
</a>

Related

PHP 5.3 write contents to plain text

I am trying to make a PHP script write into a plain text file. I have done this before and it worked just fine. But it's not working this time for some reason.
Here is the HTML I am using:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="/css/feedback.css" >
<title>Questions, Comments, Suggestions</title>
</head>
<body>
<p class="title">Questions, comments, and suggestions here!</p>
<form method="post" name="userFeedback" action="/submit.php">
<textarea id="comments" placeholder="Leave a comment or review here..."></textarea>
<textarea id="name" placeholder="Your name here"></textarea>
<textarea id="contact" placeholder="Put any means of contact you want to here (optional)"></textarea>
<br>
<input class="enter" type="submit" value="Enter">
</form>
</body>
</html>
All I want to do with this is to print out whatever is entered onto a plain .txt file with PHP 5.3. Here is the code:
$data = ($_POST["comments"] ." || ". $_POST["name"] ." || ". $_POST["contact"]);
$data = strip_tags($data);
$file = "feedback.txt";
$f = fopen($file, "a+");
fwrite($f, $data . "\n" . "\n");
fclose($f);
header ( 'Location: index.html' );
Please remember that I am using 5.3. I'm sure there's a simple error in here somewhere. Can someone help me with this? Thank you in advance!
We got it! Turns out that the PHP $_POST method looks for the "name" attribute and not the "id".

Silverstripe 3 - send email with data of foreach-loop

I want to send an email with the data of a foreach loop but I don't know how to get the data into the email body.
that's my current code
...
...
foreach($cartItems as $cartItem) {
'<strong>' . $cartItem->Amount . 'x ' . $cartItem->Title . '</strong>' . '<span>' . $cartItem->Price . ' €/St. insgesamt ' . $cartItem->Sum . '</span><br>';
}
...
...
$messageBody = "
foreach() Content should be here
";
$email->setBody($messageBody);
...
...
can someone help me?
thank you in advance
Use the built in Silverstripe Email functionality to take advantage of Silverstripe's templating with your email.
With Silverstripe you can create a template for your email and populate it with whatever data you like.
Within your send function in your controller you can set the template with setTemplate and push data into the email template with populateTemplate:
$email = new Email($from, $to, $subject);
$email->setTemplate('EmailTemplate');
$email->populateTemplate(array(
'CartItems' => $cartItems,
'PageTitle' => $this->Title
));
$email->send();
Note that $cartItems has to be a ArrayList or DataList to be able to use <% loop %> in template. If $cartItems is an array, read how to convert it to ArrayList here.
Put your template into themes/mytheme/templates/Email/EmailTemplate.ss
EmailTemplate.ss
<!DOCTYPE HTML>
<html>
<head>
...
</head>
<body>
...
<% if $CartItems %>
<% loop $CartItems %>
...
<% end_loop %>
<% end_if %>
...
</body>
</html>

How to configure WAMP and Smtp server

I have spent a significant time looking for an answer, and tried every solution without success :/
Basically I want to use wamp server to create contact form that will be sent to my mail address.
I have wamp running but for the life of me I can't figure out why I wouldn't receive the mails, I either get the 404 page when submitting the form, or lately "Warning: mail(): SMTP server response: 553 sorry, that domain isn't in my list of allowed rcpthosts".
I am now looking for a solution that will at least send the form to my address, whether it's secured or not I just want to see an actual mail successfully sent.
Thanks !
edit: here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Contact Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="page-wrap">
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"> </textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
<div style="clear: both;"></div>
</div>
</div>
</body>
</html>
--then the contact engine--
<?php
$EmailFrom = "myadress#mail.com";
$EmailTo = "myadress#mail.com";
$Subject = "Nice & Simple Contact Form by CSS-Tricks";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
--then the thanks message--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<head>
<title>A Nice & Simple Contact Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="page-wrap">
<img src="images/title.gif" alt="A Nice & Simple Contact Form" />
<p>By CSS-Tricks</p>
<br /><br />
<h1>Your message has been sent!</h1><br />
<p>Back to Contact Form</p>
</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-68528-29";
urchinTracker();
</script>
</body>
</html>
Windows does not come with a Mail Server so just calling mail() will work as far as php is concerned but the mail goes nowhere.
You either need to install a mail server or use something like the PHPMailer library to allow you to send SMTP mails via something like Yahoo or Google.

Pass value from HTML page form to a CGI program

I'm trying to create a simple program that will get the content of the webpage for the sake of my assignment.
Right now I create a very simple HTML page that will let the user enter a URL.
<html>
<head><title>URL page</title>
</head>
<body>
<form action="cgi-bin/b1.cgi" method="GET">
Enter the URL you want to see <input type="text" name="passing" size=40>
<input type="submit" value="submit">
</form>
</body>
</html>
so I just want to pass the url to my CGI program that I have so far
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use LWP::Simple;
use CGI;
use HTML::HeadParser;
#my $pass = $cgi->param('passing');
$URL = get ("$passing");
$head = HTML::HeadParser->new;
$head->parse("$URL");
print "This is the Title of the page" . $head->header('Title') . "\n\n";
print $head->header('X-Meta-Description') . "\n\n";
print $head->header('X-Meta-Keywords') . "\n\n";
print $head->header('Content-Type') . "\n\n";
print $head->header('Content-Language') . "\n\n";
exit;
So from the above code as you can see if I can get the value that pass from the GET method to the line where it say URL = get(); then I can get the content.
I tried some approch like my $pass = $cgi->param('passing'); but it gives me an error about param
Any suggestion would be so much appreciated.

Contact form submit script - HTML email problem

I have a contact form script and when the user submits it, they get an email and I get one. But there's a problem with the "message" textarea in the HTML email. It puts it all in one line.
See how I type it out:
And then in the email sent to me (HTML) its all in one line:
As you can see it is all in one line. How can I get it to not be in this line?
This is my code:
<?php
// load the variables form address bar
$subject = $_POST["subject"];
$message = $_POST["message"];
$from = $_POST["from"];
$name = $_POST["name"];
$verif_box = $_POST["verif_box"];
// remove the backslashes that normally appear when entering " or '
$message = stripslashes($message);
$subject = stripslashes($subject);
$from = stripslashes($from);
$name = stripslashes($name);
$emailContent = "Hello Nathan,
".$name." is trying to contact WeeBuild Support. Here's what they submitted:
<br /><br />
<div style='background-color:#ccc;padding:10px;border:1px solid grey;'>
Name: <strong>".$name."</strong>
<br /><br />
Email: <strong>".$from."</strong>
<br /><br />
Subject: <strong>".$subject."</strong>
<br /><br />
Message:
<br /><br />
<strong>".$message."</strong>
<br /><br /><br />
Their IP Address: <strong>".$_SERVER['REMOTE_ADDR']."</strong>
</div>
<br /><br />
To email them back, simply reply to this message.";
$emailContents = "Hello ".$name.",
Thank you for contacting WeeBuild Support! This email is to let you know that we have received your support request and that we will reply soon.
For your record, here is what you submitted:
-----------------------------------------------------------------------------
Your Name: ".$name."
Your Email: ".$from."
Subject: ".$subject."
Message:
".$message."
-----------------------------------------------------------------------------
In the meanwhile, make sure to add support#weebuild.biz to your contact list/safe senders list so our emails don't end up in your junk folder.
We will be with you shortly!
Kind regards,
WeeBuild Support Team
www.WeeBuild.biz";
$emailContent = stripslashes($emailContent);
$emailContents = stripslashes($emailContents);
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if verification code was correct send the message and show this page
mail("nathan#weebuild.biz", 'WeeBuild Contact Form: "'.$subject.'"', $emailContent, $headers);
mail($from, 'Thank you for contacting WeeBuild Support!', $emailContents, "From: support#weebuild.biz");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
} else if(isset($message) and $message!=""){
// if verification code was incorrect then return to contact page and show error
header("Location: index.php?name=$name&subject=$subject&from=$from&message=".urlencode($message)."&wrong_code=true");
exit;
} else {
echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">
<html><head>
<title>Access Denied</title>
<style type=\"text/css\">
body {
font-family: Arial, sans-serif;
}
</style>
</head><body>
<h1>Access Denied</h1>
<p>This page cannot be accessed directly. The needed variables to submit were not provided.</p>
</body></html>";
exit;
}
?>
Note: $emailContent is the email that goes to me and $emailContents is the email that goes to the user.
I tried using the str_replace() and that just caused parsing problems and I could not get that to work. I'm sure I wasn't using it right.
Can someone help me with this? Any help is highly appreciated.
use nl2br();
So edit this snippet
Message:
".$message."
to
Message:
".nl2br($message)."
You can use nl2br() function on $message to change newlines into <br /> tags.