News:

Looking for documentation? Take a look on our wiki

Main Menu

Phpmailer

Started by jomercillo, July 09, 2013, 17:42:23 PM

Previous topic - Next topic

jomercillo

Hello! I put a block, in my index.php, to appear when you visit the page, that ask your email if you want to be sent offers. The codes reply automatically via email with our offers. The question is that, this morning works for once but after that I couldn't get the server to send again emails to the clients. I have joomla 2.5.11 and virtuemart 2.0.20b.
The structure of the index is:
<?php



defined
('_JEXEC') or die;

include_once(
JPATH_ROOT "/templates/" $this->template '/setup.php');

/* The following line loads the MooTools JavaScript Library */

JHtml::_('behavior.framework'true);



/* The following line gets the application object for things like displaying the site name */

$app JFactory::getApplication();

?>


<?php echo '<?'?>xml version="1.0" encoding="<?php echo $this->_charset ?>"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->language?>" lang="<?php echo $this->language?>" dir="<?php echo $this->direction?>" >

  <head>
<jdoc:include type="head" />
<?php 
    
include_once(JPATH_ROOT "/includes/phpmailer/class.phpmailer.php");
    include_once(
"KoolPHPSuite/KoolControls/KoolAjax/koolajax.php");
    include_once(
JPATH_ROOT "/libraries/phpmailer/smtp.php");
    
    
$koolajax->enableFunction("fun_envia");  
    
$koolajax->enableFunction("fun_Comprueba_Existencia");          
?>


<style>
    .fondo_negro {
    position:absolute;
    left:0px;
    top:0px;
    display: none;
    width: 100%;
    height: 100%;

    z-index: 9999;
    opacity: 0.7;
    }
   
    #capa_info {
    display: none;
    top :5%;
position:absolute;
left:50%;
margin-left:-396.5px;
width: 793px;
    height: 515px;
    padding: 20px;       
    background-color: #fff;
    border: 1px solid black;
    z-index: 10000;
    overflow: auto;
    }
   
    .field {
    font-family: Tahoma;
    font-size: 12px;   
    }

</style>
</head>
<?php

if ($_SERVER['REQUEST_URI']==="/") {
if ($_SESSION["Ya_Registrado"]==1) {
?>

<body id="bg" >
<?php
}
else {
?>

<body id="bg" onLoad="mostrar_info()"  >
<?php
}
}
else {
?>

<body id="bg">
<?php
}

?>




    <!-- The following JDOC Head tag loads all the header and meta information from your site config and content. -->

    <jdoc:include type="head" />



    <!-- The following line loads the template CSS file located in the template folder. -->

    <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" type="text/css" />

    <!--[if IE 8]>

    <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/fix_ie.css" type="text/css" />

    <![endif]--> 

    <!-- The following line loads the template JavaScript file located in the template folder. It's blank by default. -->

    <script type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/template.js"></script>

  </head>

  <body id="bg">
<?php echo $koolajax->Render(); ?>

    <div id="header">

      <div id="head_left">

        <div class="mail">

                  </div>

        <div class="logo">

          <a href="<?php echo JURI::base(); ?>"><img class="iePNG" src="<?php echo $this->baseurl ?>/templates/medical_equipment/images/logo.png" alt="logo" /></a>

        </div>

      </div>

      <div id="head_right">

        <div class="phones">

          <img class="iePNG" src="<?php echo $this->baseurl ?>/templates/medical_equipment/images/phones.png" alt="Call us" />

        </div>

        <div class="clear"></div>

        <div class="cart_currency">

          <div class="currency">

            <?php if ($this->countModules('currency')) : ?>

              <jdoc:include type="modules" name="currency" />

            <?php endif; ?>

          </div>

          <div class="topcart">

            <?php if ($this->countModules('topcart')) : ?>

              <jdoc:include type="modules" name="topcart" />

            <?php endif; ?>

          </div>

          <div class="clear"></div>

          <div class="bg_img">

          </div>

        </div>

      </div>

    </div>

    <div class="clear"></div>

    <div id="body_width">

      <div id="topline">

        <div id="menu_search">

          <div class="topmenu">

            <?php if ($this->countModules('topmenu')) : ?>

              <jdoc:include type="modules" name="topmenu" />

            <?php endif; ?>

          </div>

          <div class="search">

            <?php if ($this->countModules('search')) : ?>

              <jdoc:include type="modules" name="search" />

            <?php endif; ?>

          </div>

        </div>

      </div>

        <div id="leftcollumn">

          <div class="categories">

            <?php if ($this->countModules('categories')) : ?>

              <jdoc:include type="modules" name="categories" style="mod_title" />

            <?php endif; ?>

          </div>

          <div class="clear"></div>

          <div class="left_banner">

            <?php if (JFactory::getURI()->toString() == JURI::base()) : ?>

              <jdoc:include type="modules" name="left_banner" />

            <?php endif; ?>

          </div>

          <div class="cart">

            <?php if ($this->countModules('cart')) : ?>

              <jdoc:include type="modules" name="cart" style="mod_title" />

            <?php endif; ?>

          </div>

          <div class="clear"></div>

          <div class="specials">

            <?php if ($this->countModules('specials')) : ?>

              <jdoc:include type="modules" name="specials" style="mod_title" />

            <?php endif; ?>

          </div>

        </div>

        <div id="rightcollumn">

          <?php if (JFactory::getURI()->toString() == JURI::base()) : ?>

          <div class="slider">

            <?php if ($this->countModules('slider')) : ?>

              <jdoc:include type="modules" name="slider" />

            <?php endif; ?>

          </div>

          <div class="clear"></div>

          <div class="right_banners">

            <jdoc:include type="modules" name="right_banners" />

          </div>

          <div class="clear"></div>

          <div class="scroller">

            <?php if ($this->countModules('scroller')) : ?>

              <jdoc:include type="modules" name="scroller" style="mod_title" />

            <?php endif; ?>

          </div>

          <?php endif; ?>

            <?php if ($this->getBuffer('message')) : ?>

              <jdoc:include type="message" />

            <?php endif; ?>

              <jdoc:include type="component" />

              <jdoc:include type="modules" name="spec" style="mod_title" />

        <div class="clear"></div>

        <div id="small_banners">

          <?php if ($this->countModules('small_banners')) : ?>

            <jdoc:include type="modules" name="small_banners" />

          <?php endif; ?>

        </div>             

        </div>

        <div id="rightbannercolumn" class="rightbannercolumn">

          <h1></h1> <!-- <h1>Test</h1> -->

          <div class="rightbancolumn_mod">

            <jdoc:include type="modules" name="rightbannercolumn" style="rightbannercolumn" />

          </div>

        </div>

       

        <div class="clear"></div>

        <div id="big_banners">

          <?php if ($this->countModules('big_banners')) : ?>

            <jdoc:include type="modules" name="big_banners" />

          <?php endif; ?>

        </div>

        <div class="clear"></div>

        <div id="socials" style="display:none">

          <?php if ($this->countModules('socials')) : ?>

            <jdoc:include type="modules" name="socials" style="mod_title" />

          <?php endif; ?>

        </div>

        <div id="bottom_menus">

          <div class="your_acc">

            <?php if ($this->countModules('your_acc')) : ?>

              <jdoc:include type="modules" name="your_acc" style="mod_title" />

            <?php endif; ?>

          </div>

          <div class="our_offers">

            <?php if ($this->countModules('our_offers')) : ?>

              <jdoc:include type="modules" name="our_offers" style="mod_title" />

            <?php endif; ?>

          </div>

          <div class="information">

            <?php if ($this->countModules('information')) : ?>

              <jdoc:include type="modules" name="information" style="mod_title" />

            <?php endif; ?>

          </div>

        </div>

        <div class="clear"></div>

      </div>

    </div>

    <div class="clear"></div>

    <div id="footer">

      <div id="foot_left">

        <div class="foot_menu">

          <?php if ($this->countModules('foot_menu')) : ?>

            <jdoc:include type="modules" name="foot_menu" />

          <?php endif; ?>

        </div>

        <div class="clear"></div>

        <div class="copyright">

          <div style="font-size:13px; color:#888;">&copy;<?php echo  Date'Y' ) ;?>.</div>

          <div class="clear"></div>

          <div>designed by <a href="" title="Website Templates"></a> <a href="" title=" Para Mascotasyaccesorios"></a>

          </div>

        </div>

      </div>

      <div id="foot_right">

        <div class="share">

          <?php if ($this->countModules('share')) : ?>

            <jdoc:include type="modules" name="share" />

          <?php endif; ?>

        </div>

        <div class="payments">

          <?php if ($this->countModules('payments')) : ?>

            <jdoc:include type="modules" name="payments" />

          <?php endif; ?>

        </div>

        <div class="co">

          <?php if($this->countModules('2co')) : ?>

            <jdoc:include type="modules" name="2co" />

          <?php endif; ?>

        </div>

        <div class="paypal">

          <?php if($this->countModules('paypal')) : ?>

            <jdoc:include type="modules" name="paypal" />

           <?php endif; ?>

        </div>

      </div>

    </div>
<div id='capa_info'>
<div style="text-align:right; background-color:#f8f9fb;margin-bottom: -17px;width: 793px;"><img src="img/cerrar.png" onClick="ocultar_info()" ></div>
<div style="text-align:center" > <br> <img src="img/cabecera_1.png" ></div>

<div id='noticia' style="margin-top: -5px;">
<form name="datos_form">
<center>
<div style="background-color:#eeeff1;width:793px" >
<br>
<table align="center" width="70%" >
<tr>
<td width="1%" align="left"><img src="img/cabecera_2.png"></td>
<td><input class="field" style="border:1px solid #ccc6c6; height:35px; width:338px; " type="text" size="50" name="mail"></td>
</tr>
</table>
<br>
                <img src="img/animales.png" width=340px style="text-align:left" >
<img src="img/enviar.png" style="cursor:pointer; text-align:right; " onClick="fun_test()" >
<br>

</div>
</center>
</form>
</div>
</div>


</div>
<div id='fondo' class='fondo_negro'><div>

<script type="text/javascript">

function mostrar_info(){
document.getElementById('capa_info').style.display = 'block';
document.getElementById('fondo').style.display = 'block';
}
   
function ocultar_info(){
document.getElementById('capa_info').style.display = 'none';
document.getElementById('fondo').style.display = 'none';
}

function fun_test() {
if (document.datos_form.mail.value==="") {
alert("Introduzca los campos obligatorios.");
return;
}

if (!funJS_Formulario_Validar_Campo_Mail(document.datos_form.mail.value)) {
  document.datos_form.mail.focus();
  alert("Introduzca un correo v\u00E1lido.");
  return;
  }
 

/*
var intResultado = koolajax.callback(fun_Comprueba_Existencia(document.datos_form.mail.value));

if (intResultado>0) {
alert("E-mail ya existente.");
return;
}
*/

var intResultado = koolajax.callback(fun_envia(document.datos_form.mail.value));

if (intResultado==1) {
alert("Revisa tu email para obtener tu usuario y tu CUPON DE DESCUENTO.");
}
ocultar_info();
}

function funJS_Formulario_Validar_Campo_Mail(strMail) {
var eMail=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
return(eMail.test(strMail));
}

</script>
  </body>

</html>


And the file setup.php filled with the right parameters of the server (host, username, pass,..)
<?php
/*--------------------------------------------------------------
# Copyright (C) 2008 Gavick.com. All Rights Reserved.
# License: Copyrighted Commercial Software
# Website: http://www.gavick.com
# Support: support@gavick.com 
---------------------------------------------------------------*/

defined'_JEXEC' ) or die( 'Restricted index access' );




function fun_envia($strEmail) {
$_SESSION["Ya_Registrado"]=0;
$booreturn 1;
$nombre $strEmail;

$db JFactory::getDBO();

$strPassword fun_Retorna_Password();

$query "INSERT INTO `entradas_form` (`Nombre`,`Mail`,`Fecha`,`Hora`,`IP`,`Password`) VALUES ('".$nombre."','".$strEmail."','".date("Y-m-d")."','".date("H:i:s")."','','".$strPassword."')";
if ($db->setQuery($query)) { $booreturn 1; }
if ($db->query()) { 
$booreturn 1

else {
$f fopen("TestDB.log","w");
fwrite($f,$db->stderr());
fclose($f);
}

$body "<body style=\"margin: 10px;\">"
"Hello."

"<br></body>";

$mail             = new PHPMailer();
$mail->IsSMTP();
$mail->Host       "the_name_of_my_host"  
$mail->SMTPDebug  2;                                                                 
                                           
$mail->SMTPAuth   true
$mail->SMTPSecure "";                 
$mail->Port       26;                   
$mail->Username   "username"
$mail->Password   "password";        

$mail->AddReplyTo("email","name");
$mail->Subject    "Subject";
$mail->AltBody    "Altbody";
$mail->MsgHTML($body);
 
$mail->AddAddress($strEmail$nombre);  

// $mail->AddAttachment("images"."/".$_FILES["fileField"]["name"]);      

if($mail->Send() != 1) { $booreturn 0; }  else { $_SESSION["Ya_Registrado"]=1; }

return ($booreturn);
}

function fun_Retorna_Password() {
$strCharPassword"ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
$strPassword "";

// Generamos Usuario y Password de Forma aleatoria
for ($i=0$i<12$i++) {
$strPassword.=substr($strCharPassword,rand(0,strlen($strCharPassword)),1);
}
return ($strPassword);
}

function fun_Comprueba_Existencia($strEmail) {
$booExiste = -1;
$db JFactory::getDBO();
$query "SELECT * FROM `entradas_form` WHERE (`Mail` = '".$strEmail."' ) ";
if ($db->setQuery($query)) {
if ($res $db->query()) {
$count $db->getNumRows($res);
if ($count>0) {
$booExiste 1;
}
}
}
return ($booExiste);
}

?>

jenkinhill

That is not something that VirtueMart has a role in, you are just adding the code to your Joomla template. The right place to ask is on http://forum.joomla.org/ or on gavick.com as you seem to be using their code.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum