Draw squares within a php forms - php

I am new to php coding and in my project I would like to draw squares around the square-shaped php forms I made.
However, I have difficulties in doing so... As you can see the the code below, I was testing and try to draw a square with a div below but it is not showing... Can someone please suggest what have I done wrong please?
Cheers,
Karen
<?php
$to = 'sender#email.com';
$subject = 'HTML Form in HTML Email';
$headers = "From: receiver#email.com\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\n";
$message = '<html><body>';
$message .='<div style="width:10px; height:10px; border:1px black !important;">';
$message .='</div>';
$message .= '<form action="http://mysite/process.php" method="post" name="emailCrossword" target="_blank">';
$crossword = array();
$crossword = 6;
for ($i=0; $i<=$crossword.length; $i++){
echo
$message .= '<input type="text" style="width: 13px; text-transform:capitalize;" placeholder="text-align:center;" name="commentText" maxlength="1"></input>';
}
$message .= '<br/>';
$message .= '<br/>';
$message .= '<input type="submit" name="crossword" value="Submit your crossword" /> </form>';
$message .= '</body></html>';
mail($to, $subject, $message, $headers);
?>

I'm not sure what you are trying to achieve, but your css shorthand for the border is wrong:
border:1px black !important;
Should be:
border:1px solid black !important;
For a solid line obviously...

Related

PHP mail function fails with "message has lines too long for transport"

I'm using PHP 7.4.30 and I'm totally new to PHP.
$subject ="My subject";
$message = '<html><body>';
$message .= '<div style="text-align: center; width: 100%; background-color: #fff;">';
$message .= '<div class="info"> </div>';
$message .= '<table style="text-align: justify; margin: auto; background-color: #ebebeb; border: 1px solid #e7e7e7; width: 600px;" cellspacing="0" cellpadding="0" bgcolor="#ebebeb" align="center">';
$message .= '<tbody>';
$message .= '<tr style="line-height: 0px;">';
$message .= '<td style="line-height: 0';
$from = "My website<robot#website.com>";
$replyto = "website#website.com";
$headers = 'Content-Type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$headers .= 'Reply-To: '. $replyto . "\r\n";
$headers .= 'Bcc: xxx#xxx.com';
$message = str_replace("\n.", "\n..", $message);
mail($to, $subject, $message, $headers);
Looking at the delivery track from the server, I see the error message:
"message has lines too long for transport"
Can anyone help?
I have recently faced this issue. An easy solution to this issue is replacing this line
$message = str_replace("\n.", "\n..", $message);
with
$message = wordwrap($message, 70,"\r\n");

Email Function not working even after correcting code. I am not getting why not sending emal

Following is my php code for email function which is not sending email and i am not getting where the mistake is. Form data is posting properly but mail is not going.
$imgSrc = "logo1.png";
$bg = "background.jpg";
$subjectPara1 = "Dear admin";
$subjectPara2 = $_POST["message"];
$subjectPara4 = $_POST["email"];
$subject = $_POST["subject"];
$subjectPara3 = $_POST["author"];
$message = '<!DOCTYPE HTML><html>'.
'<head>'.
'<title>Email notification</title>'.
'</head>'.
'<body style="background-image: url('.$bg.');background-size: cover;">'.
'<div id="header" style="width: 80%;height: 60px;margin: 0 auto;padding: 10px;color: #fff;text-align: left;font-family: Open Sans,Arial,sans-serif;">'.
'<img height="50" width="220" style="border-width:0" src="'.$imgSrc.'" >'.
'</div>'.
'<div id="outer" style="width: 80%;margin: 0 auto;margin-top: 10px;">'.
'<div id="inner" style="width: 78%;font-family: inherit;font-size: 15px;font-weight: normal;line-height: 1.4em;color: #fff;margin-top: 10px;">'.
'<p>'.$subjectPara1.'</p>'.
'<p>'.$subjectPara2.'</p>'.
'<p><br/>Regards,<br/>'.$subjectPara3.'</p>'.
'<p>'.$subjectPara4.'</p>'.
'</div>'.
'</div>'.
'<div id="footer" style="width: 80%;height: 40px;text-align: center; padding: 10px; font-family: inherit; font-size: 15px; color: #fff;">'.
'All rights reserved # 2016'.
'</div>'.
'</body></html>';
$to = 'test#exmple.com';
$from = $subjectPara4;
$headers = 'From: test#exmple.com\r\n';
$headers .= 'Reply-To: test#exmple.com\r\n';
$headers .= 'MIME-Version: 1.0\r\n';
$headers .= 'Content-Type: text/html; charset=ISO-8859-1\r\n';
if(mail($to, $subject, $message, $headers))
{
echo "<script>window.location='index.php';</script>";
}
Kindly help me to resolve this.

generating a html email in php on submit

i am trying to figure out writing html in php file. it seems that php does not recognise all the html tag like font, img. it gave an error. I tried echo 'html stuff'; but it dont seem to work as well.
I have left out the other $var declaration in the code below. the script is working except when i tried to add font size or img tags.
<?php
header("Content-type: html");
$message = "
<!DOCTYPE html>
<html>
<head>
<title>New Loan Enquiry</title>
</head>
<body>
<h2><strong>Time of Enquiry: $today</strong></h2>
Name: $name<br>
Email: $email<br>
Contact: $contact<br>
Buy_Stage: $buystage<br>
Property Type: $pty_type<br>
Property Stage: $pty_stage<br>
Purchase Price: $purchaseprice<br>
Loan Amount: $loanamt<br>
Rate Type: $rate_type<br>
Comments: $comments<br><br>
</body>
</html>
";
mail($to,$subject,$message,$headers);
?>
where did i go wrong? It recognize h2 but not h1 or h3.
do i have to do like
echo ' html';
for each html code line?
Please check mail() in documentation.
To send email with html content you need to do this way:
<?php
$to = 'aidan#example.com';
// subject
$subject = 'subject of email';
// message
$message = 'some html content...';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
and you don't need to use:
header("Content-type: html");
you need to add
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <from#example.com>' . "\r\n";
$headers .= 'Cc: cc#example.com' . "\r\n";
and remove
header("Content-type: html");
I find it best to style Html email in php by using tables and inline styles like below. here is a link to reference. Link, Sadly internal and external style sheets don't always work across different email clients.
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$message = '<html>';
$message .= '<head>';
$message .= '<title>New Loan Enquiry</title>';
$message .= '</head>';
$message .= '<body>';
$message .= '<h2><strong>Time of Enquiry: $today</strong></h2>';
$message .= '<img src="http://YOUR_IMAGE_URL"/>;
$message .= '<table width="auto" border="0" cellspacing="3px" cellpadding="0">';
$message .= '<tr><td><strong>Name:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$name</td></tr>';
$message .= '<tr><td><strong>Email:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$email</td></tr>';
$message .= '<tr><td><strong>Contact:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$contact</td></tr>';
$message .= '<tr><td><strong>Buy_Stage:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$buystage</td></tr>';
$message .= '<tr><td><strong>Property Type:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$pty_type</td></tr>';
$message .= '<tr><td><strong>Property Stage:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$pty_stage</td></tr>';
$message .= '<tr><td><strong>Purchase Price:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$purchaseprice</td></tr>';
$message .= '<tr><td><strong>Loan Amount:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$loanamt</td></tr>';
$message .= '<tr><td><strong>Rate Type:</strong></td>';
$message .= '<td>\$rate_type</td></tr>';
$message .= '<tr><td><strong>Comments:</strong></td>';
$message .= '<td style=" font-weight:300 color:#CC0000">\$comments</td></tr>';
$message .= '</table>';
$message .= '</body></html>';
mail($to,$subject,$message,$headers);
?>

do while repeated region in variable php

Trying to build contact page. I would like to be able to send multiple emails in one time. email addresses have been pulled in from database. I am managing getting them all with do while. However to add "bcc" all addresses I need them to be in one variable for example $emails. I cannot seem to figure out how to do that. This is what I have so far:
$username = $_POST['Username'];
$email = $_POST['email'];
$to="email goes here";
$from= $_POST['email'];
$subject= "Raiding Team Announcement";
$footer="© Copyright 2015 All Rights Reserved ";
$message .= '<html><body>';
$message .= '<div style="width:100%; background-color:#333;">';
$message .= '<h1 style="font-size:50px; color:#FFCC00; text- align:center; display:block; padding-bottom:15px; border-bottom:1px solid #AA0114; ">HellscreamsFury</h1>';
$message .='<h2 style="font-size:32px;color:#f37e0e; text-align:center;">' .$_POST["Username"].' says:</h2>';
$message .='<div style="margin:30px; padding:10px; border:1px solid #404040; margin-bottom:50px;">';
$message .='<p style="font-size:18px; color:#ccc;">' .$_POST["message"]. '</p>';
$message .= '</div>';
$message .= '<div style="border-top:1px solid #AA0114;">';
$message .='<p style="font-size:12px; color:#fff; text-align:center; padding: 20px 0 50px 0;">' .$footer. '</p>';
$message .= '</div>';
$message .= '</div>';
$message .= '</body></html>';
$headers .= "From: " . $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if(mail($to,$subject,$message,$headers)){
header("Location: ../announcments.php?aid=43");
}
else{
header("Location: ../announcments.php?aid=44");
}
This snippet pulls in my emails:
<?php do { ?>
<?php echo $row_rs_contact_team['email']; ?>
<?php } while ($row_rs_contact_team = mysql_fetch_assoc($rs_contact_team)); ?>
I would need them to sit in one variable - let's say $emails. How do I do that? Also emails are pulled in while checking user_id, but sometimes user_id repeats - is there a way to pull that email in once instead of pulling let's say three times?
Do can do it by iterating it into a while loop and concat it and adding a comma near to it.
$CountingQuery = "SELECT * FROM users";
$ExecutingCountingQuery = $Connection->query($CountingQuery);
$Bcc = ''; // Declaring a Variable
while($row = $ExecutingCountingQuery->fetch_array())
{
$Bcc .=$row['email'].',';
}
echo $Bcc; // Now $Bcc is your expected output
//The output will be something like
//sa#sysaxiom.com,test#sysaxiom.com,demo#sysaxiom.com,admin#sysaxiom.com,
Note :
I don't know what name you use to store the email coloumn. So i used the name email for the email column.
Also I have used * where you can replace it for your need.

How to send HTML-formatted message with standard mail function in PHP

I am trying to use the following in my contact us form to receive nicely formatted html email from my visitors:
$message .='<table width="800" border="0" cellspacing="3" cellpadding="3" style="margin-bottom: 20px">';
$message .='<caption style="text-align:left;background:#eee;padding:5px;font-size:18px;font-weight:bold;">Webmail</caption>';
$message .='<tr><td width="200"><strong>Date</strong></td><td width="600" style="border:1px solid #ccc;">'.$todayis.'</td></tr>';
$message .='<tr><td width="200"><strong>From</strong></td><td width="600" style="border:1px solid #ccc;">'.$name.'</td></tr>';
$message .='<tr><td width="200"><strong>Email</strong></td><td width="600" style="border:1px solid #ccc;">'.$email.'</td></tr>';
$message .='<tr><td width="200"><strong>Subject</strong></td><td width="600" style="border:1px solid #ccc;">'.$recipient.'</td></tr>';
$message .='</table>';
$message .= '<div style="width:770px;background:#eee;padding:15px;">';
$message .= '<div style="font-weight: bold; font-size: 18px;padding-bottom: 10px;">Your Message</div>';
$message .= $message;
$message .= '</div>';
$message .='<table width="800" border="0" cellspacing="3" cellpadding="3" style="margin-bottom: 20px">';
$message .='<caption style="text-align:left;background:#eee;padding:5px;font-size:18px;font-weight:bold;">Webmail Data</caption>';
$message .='<tr><td width="200"><strong>IP Address</strong></td><td width="600" style="border:1px solid #ccc;">'.$ip.'</td></tr>';
$message .='<tr><td width="200"><strong>Browser Info</strong></td><td width="600" style="border:1px solid #ccc;">'.$httpagent.'</td></tr>';
$message .='<tr><td width="200"><strong>Referral</strong></td><td width="600" style="border:1px solid #ccc;">'.$httpref.'</td></tr>';
$message .='</table>';
$headers = "From: " . $email . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "X-Priority: 1\r\n";
$sent = mail($to, $subject, $message, $headers);
The problem I have is that when I use text/html the email shows as sent but I am not getting it, when I am changing it to text/plain everything works fine except that I get everything in plain text without any HTML formatting.
I am on my own dedicated Apache server, running Plesk 12.0.18 and CentOS6.6 do I need to configure anything on the server? I have tried to configure the email to receive everything in HTML format, but seems like it did not work.
Any help is appreciated.
Php Html email
<?php
$to = "abc#gmail.com";
$subject = "PUT_SUBJECT_HERE";
$mail_body = '<html>
<body bgcolor="#573A28" topmargin="25">
Put HTML content here with variables from PHP if you like
Variable display Example: ' . $subject . '
<h1>this is a heading</h1>
</body>
</html>';
//$headers = "From: abc#gmail.com";
//$headers .= "Content-type: text/html";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <abc#gmail.com>' . "\r\n";
mail($to, $subject, $mail_body, $headers);
?>
Enjoy this code

Categories