Setting up PEAR mail on Scotch Box

You have Vagrant and Scotch Box installed. You still need to install Pear.

$ vagrant ssh
$ sudo apt-get -y install php-pear
$ sudo pear install mail_mime

In your PHP script

include_once('Mail.php');
include_once('Mail/mime.php');

Parameters to define SMTP Scotch Box

$params["host"] = "127.0.0.1";
$params["port"] = 1025;
$params["Date"] = date('r',time());
$mail = Mail::factory("smtp",$params);
...

Catch mails in Mailhog at http://192.168.33.10:8025

Getting started with WAMP: setting up

Memory exhausted problem

“Allowed memory size of 134217728 bytes exhausted”
I encountered this problem a few times, and setting memory_limit to a higher value didn’t seem to work

In php.ini:
memory_limit = -1;

Changing www root on WAMP

Open httpd.conf

Change

Listen 0.0.0.0:80
Listen [::0]:80

to

Listen 127.0.0.1:80
Listen [::1]:80

Change

DocumentRoot "C:/wamp/www/"

to

DocumentRoot "C:/Users/name/Sites/localhostwamp/"

Change

</pre>
<Directory "C:/wamp/www/">
<pre>

to

</pre>
<Directory "C:/Users/.../Sites/localhostwamp/">
<pre>

Setting mySQL password

go to shell (right click mysql shell in taskbar)

update mysql.user set Password = password('yourPasword') where User = 'root';
flush privileges;

go to phpmyadmin directory c:\…\wamp2.5\apps\phpmyadmin4.1.14\config.inc.php

replace:

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';

with

$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['password'] = '';

Or watch this dummy video tutorial:

Set login session to something less restrictive for testing purposes

in your config.inc.php file (apps/phpmyadmin…)

$cfg['LoginCookieValidity'] = 604800; /* 1 week */
$cfg['MaxNavigationItems'] = 1000;

mysql error logging

add these lines to my.ini

log-queries-not-using-indexes
log-warnings
long_query_time = 2
log=C:/Webservers/wamp2/logs/querylog.log
log-slow-queries=C:/Webservers/wamp2/logs/SlowQueryLog.log

import sql-data into mySQL database

Right click Wamp icon in taskbar > mySQL

show databases;
use <databasename>;
source c:\Temp\queries.sql;

mysqldump in wamp (not via mysql console!)

Go to the wamp mysql directory via cmd prompt

cd c:\Webservers\wamp2\bin\mysql\mysql5.6.17\bin\

Now ‘all’ mysql commands are available:

mysqldump -u root -p dbname table1 table2 > output.sql

Multiline regular expression problem in PHP 5.3.3

Recently I came across a very strange behaviour in a regular expression I wrote years ago.

The webserver upgraded to PHP 5.3.3 and it suddenly stopped working.

Case as follows: I use PHP to read a text-file and with the aid of PCRE (preg_match & preg_split) I look for certain matches in that text-file. The program splits different paragraphs into seperate records. But suddenly preg_split stopped working:

<?php
$paragraphs = preg_split("/\n\n/",$contents_of_file);
?>

Multiple newlines could not be detected, whereas

<?php
$lines = preg_split("/\n/",$contents_of_file);
?>

generated no problem at all. At first I thought I had to use the multiline modifier /m but that didn’t work out either.

Although a HEX editor didn’t indicate any carriage returns in the text-file I managed to get things working by doing this:

<?php
$paragrapgs = preg_split("/\r?\n\r?\n/",$contents_of_file);
?>

Curious thing: previous and newer versions of PHP (e.g. 5.3.8 in a XAMPP test environment) did not require to look for possible occurrences of carriage returns (\r).

Aan de slag met Mercury mail voor XAMPP

Om lokaal wat programmeerwerk als voorbereiding op een live omgeving te verrichten, is XAMPP de ideale omgeving. XAMPP komt pas echt tot zijn recht met de opstelling van een eigen mailserver (Mercury Mail) waarmee je lokaal het verzenden van mails kan testen.

De uitgebreide versie van XAMPP bevat zo’n SMTP service. Bij een eerste kennismaking word je overstelpt door een hele reeks vensters die kris kras op het scherm staan. Om hierin wat wegwijs te raken, is er een uitstekende videotutorial op YouTube:

Een van de belangrijkste zaken die je moet weten bij dit programma is dat voor quasi elke aanpassing het programma opnieuw moet opstarten omdat Mercury Mail in XAMPP geen service is!

De basisinstellingen

  • Configuration: volgende protocul modules aanvinken:
    • Mercury S SMTP server
    • Mercury P POP3 server
    • Mercury E, SMTP end to end client delivery client
    • Mercury D Distributing POP3 client,
    • Mercury I Iamp4 server
  • Configuration
    • Core module
    • Local domains > add local domain
      • Localhost
      • mydomain.com
  • Configuration
    • Mercury S
    • Connection control
    • Uncheck “do not permit SMTP relaying of non-local mail”
  • Configuration
    • Mercury E
    • DNS Servers (open DNS): 208.67.222.222,208.67.220.220
  • Configuration
    • Manage local users: een testgebruik definiëren
      Het is best dat je geen gebruik maakt van postmaster@localhost, omdat deze standaard alle foutberichten opvangt.
    • Username: root
      Personal name: root
      Password: pass

Het enige wat je nu nog moet doen is de configuratie van deze local mail account in je favoriete e-mailprogramma. Daarin volg je dezelfde werkwijze alsof je een remote mailserver zou aanspreken, maar bij de serversettings plaats je gewoon ‘localhost’.

De vooraf gedefinieerde accounts hebben volgende paswoorden:

  • Postmaster: Postmaster (postmaster@localhost)
  • Administrator: Admin (admin@localhost)

User: newuser
Password: wampp