Click to See Complete Forum and Search --> : Mail colon trouble (html format)
whisher06
12-24-2006, 04:39 AM
Hi.
In a nutshell I've to send a link
within a html message.
With this string:
"<a href=http//www.blogial.net/index.php?confirm="
the script works fine and the recipient get the email (but the link doesn't work)
With this string:
"<a href=http://www.blogial.net/index.php?confirm="
the script works fine but the recipient don't get the email ..........
I think the problem is the colon.
Do you have any tip ?
Bye.
Ps.
BTW Season's Greetings :D
Tyree
12-24-2006, 09:22 AM
a colon within a string declaration has no bearing at all on the outcome of the script. It's just a character in a string.
Post more of your code so we can try to help you further.
whisher06
12-24-2006, 10:55 AM
a colon within a string declaration has no bearing at all on the outcome of the script. It's just a character in a string.
I agree with you but with the colon it doesn't work :(
Code:
<?php
/**
* Abstract class used for email sender implementation classes
*
* @package mail
* @author gustavo.gomes
* @copyright 2006
*/
abstract class AbstractMail {
const CRLF = "\n";
const HIGH_PRIORITY = 2;
const NORMAL_PRIORITY = 3;
const LOW_PRIORITY = 4;
protected $to = array();
protected $fromName;
protected $fromMail;
protected $subject;
protected $contentType;
protected $charset;
protected $priority = 2;
protected $headers = array();
protected $body;
public function __construct($to, $subject, $fromName="", $fromMail="") {
$this->to[] = $to;
$this->subject = $subject;
$this->fromName = $fromName;
$this->fromMail = $fromMail;
$this->init();
}
private function init() {
if ($this->fromName != "" && $this->fromMail != "") {
$this->addHeader("From: ".$this->fromName." <".$this->fromMail.">");
$this->addHeader("Reply-To: ".$this->fromName." <".$this->fromMail.">");
} else if ($this->fromName == "" && $this->fromMail != "") {
$this->addHeader("From: ".$this->fromMail);
$this->addHeader("Reply-To: ".$this->fromMail);
}
}
public function getPriority() {
return $this->priority;
}
public function setPriority($priority) {
$this->priority = $priority;
}
public function getContentType() {
return $this->contentType;
}
public function getCharset() {
return $this->charset;
}
public function addTo($mail) {
$this->to[] = $mail;
}
public function addCC($mail) {
$this->addHeader("CC:".$mail);
}
public function addBCC($mail) {
$this->addHeader("BCC:".$mail);
}
public function addHeader($header) {
$this->headers[] = $header.self::CRLF;
}
protected function buildTo() {
return implode(", ",$this->to);
}
protected function buildHeaders() {
$headers = "";
if (count($this->headers) > 0) {
for ($i = 0;$i < count($this->headers);$i++)
$headers .= $this->headers[$i];
}
return $headers;
}
protected function createMessageHeaders($contentType, $encode="") {
$out = "";
if ($encode != "")
$out .= "Content-type:".$contentType."; charset=".$encode.self::CRLF;
else
$out .= "Content-type:".$contentType.";".self::CRLF;
return $out;
}
public static function validateAddress($mailadresse) {
if (!preg_match("/[a-z0-9_-]+(\.[a-z0-9_-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})/i",$mailadresse))
return false;
return true;
}
public function resetHeaders() {
$this->headers = array();
$this->init();
}
public abstract function setBodyHtml($html, $charset="iso-8859-1");
public abstract function setHtml($html, $charset="iso-8859-1");
public abstract function setBodyText($text);
public abstract function send();
}
/**
* Class to send simple emails in Text and HTML formats
*
* @package mail
* @author gustavo.gomes
* @copyright 2006
*/
class Mail extends AbstractMail {
public function __construct($to, $subject, $fromName="", $fromMail="") {
parent::__construct($to, $subject, $fromName, $fromMail);
}
public function setBodyHtml($html, $charset="iso-8859-1") {
$this->contentType = "text/html";
$this->charset = $charset;
$this->body = "";
$this->body .= "<html><head>";
$this->body .= "<meta http-equiv=Content-Type content=\"text/html; charset=".$charset."\">";
$this->body .= "</head><body>";
$this->body .= nl2br($html)."";
$this->body .= "</body></html>";
}
public function setHtml($html, $charset="iso-8859-1") {
$this->contentType = "text/html";
$this->charset = $charset;
$this->body = nl2br($html)."";
}
public function setBodyText($text) {
$this->contentType = "text/plain";
$this->charset = "";
$this->body = $text;
}
public function send() {
$this->addHeader("MIME-Version: 1.0");
$this->addHeader("X-Mailer: RLSP Mailer");
$this->addHeader("X-Priority: ".$this->priority);
$this->addHeader($this->createMessageHeaders($this->contentType, $this->charset));
$headers = $this->buildHeaders();
return mail($this->buildTo(),
$this->subject,
$this->body,
$headers);
}
}
//My tiny extension
class User_Mail extends Mail {
const MSG_OK = "<p class=\"validEmail\">An email has sent you. Thanks.</p>\n";
const MSG_ERROR = "<p class=\"validEmail\">The server is too busy. Please try later.</p>\n";
const MSG_SUBJECT = "This is an email from ";
const FROM_NAME = "Whisher";
const FROM_EMAIL = "xxxxx@xxxx.net";
const LINK_PATH = "<a href=http//www.blogial.net/index.php?confirm=";
const LINK_MSG = "Click here to confirm your registration at ...";
public function __construct($to) {
parent::__construct($to, self::MSG_SUBJECT.self::FROM_NAME, self::FROM_NAME, self::FROM_EMAIL);
}
public function setBodyMsg($username,$password,$lastId)
{
$bodyMsg = "<p>Username :".$username."</p>";
$bodyMsg .= "<p>Password :".$password."</p>";
$bodyMsg .= self::LINK_PATH.$lastId.">".self::LINK_MSG."</a>";
$this->setBodyHtml($bodyMsg);
$this->setPriority(AbstractMail::HIGH_PRIORITY);
if($this->send())
{
$outPut = self::MSG_OK;
}
else
{
$outPut = self::MSG_ERROR;
}
return $outPut;
}
}
?>
Blulagoon
12-24-2006, 11:49 AM
Have you tried:
const LINK_PATH = "<a href='http://www.blogial.net/index.php?confirm='>";
whisher06
12-24-2006, 02:02 PM
const LINK_PATH = "<a href='http://www.blogial.net/index.php?confirm='";
It works fine thanks a lot
buddies.
Bye and Season's Greetings :D
bradgrafelman
12-24-2006, 04:15 PM
In other words, it had nothing to do with PHP - 'href' was expecting a string value. All string values should be quote-delimited ... otherwise certain characters (spaces, colons, etc.) will confused the browser into thinking you've ended the string.
EDIT: Now that I think about it, don't all HTML values have to be delimited by quotes?
Also, don't forget to mark this thread resolved.
Tyree
12-24-2006, 06:07 PM
All of them SHOULD as of XHTML. HREF is one of the "no exceptions" ones. But some will still let you get away with no quotes...it's valid HTML, but it's not tolerated by standards compliant XHTML.
I feel like a big doof missing those quotes. Ack!
Weedpacket
12-24-2006, 11:48 PM
All of them SHOULD as of XHTML.Not quite; all of them MUST as of XHTML (like all XML), but they SHOULD as of HTML 4 (for exactly this reason; videlicet, to avoid confusion about where the attribute's value ends).
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 (http://www.ietf.org/rfc/rfc2119.txt).
Tyree
12-25-2006, 08:54 AM
SHOULD...MUST...you knew what I was saying! :D
I think saying it's "not tolerated by XHTML" is pretty clear.
Weedpacket
12-25-2006, 09:23 PM
I've been reading RFCs so much lately I've got 2119 on the brain...:D
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.